views:

52

answers:

1

hi all,

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 do i need to write code for it ? and what's the solution ?

Thanks

+1  A: 

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

Rap