开发者

WPF conditional resource selection

开发者 https://www.devze.com 2022-12-10 00:56 出处:网络
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 .

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

精彩评论

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