开发者

WPF conditional resource selection

I want to change back Color (or any other visual properties) on my control based on a boolean statement made from properties in the datacontext of the object . let me explain it with an example :

public class Node
{
    public int Min ;
    public int Max ;
}

and then I have a wpf control like :

<DockPanel x:Name="LayoutRoot" DataContext=<!-- an instance of node class --> >

now I want to select the backcolor brush from resources depeneds on if (min == max) or not .something like this :

if (min == max) 
BackColor = resources.fixedNodeBrush
else 
BackColor = resources.NodeBrush

I wanna know if it's possible to do this in xaml or 开发者_StackOverflow中文版do i need to write code for it ? and what's the solution ?

Thanks


What you want is to use a value converter. You'll convert the value of (max == min) to one brush and (max != min) to another in a utility method. Then you use that method in your XAML binding.

Take a look here: http://blogs.msdn.com/bencon/archive/2006/05/10/594886.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜