Brush
es.
Visual Basic (Declaration) | |
---|---|
Public Class BooleanBrushConverter Inherits Converter Implements IValueConverter |
C# | |
---|---|
public class BooleanBrushConverter : Converter, IValueConverter |
You can specify a brush for when the boolean is True and another one for when the boolean is False, either by setting the TrueBrush or FalseBrush properties, or by setting the TrueColor or FalseColor properties which will also set the corresponding brush property to a SolidColorBrush
of that color.
Typically you will create an instance (or two) of this converter class as resources. For example:
<go:BooleanBrushConverter x:Key="theBooleanBrushConverter" TrueColor="DodgerBlue"> <go:BooleanBrushConverter.FalseBrush> <LinearGradientBrush . . .> . . . </LinearGradientBrush> </go:BooleanBrushConverter.FalseBrush> </go:BooleanBrushConverter>
One possible use for this converter is to indicate selection:
<DataTemplate x:Key="NodeTemplate2"> <Border BorderBrush="Gray" BorderThickness="1" Background="{Binding Path=Part.IsSelected, Converter={StaticResource theBooleanBrushConverter}}" go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay}"> <StackPanel Orientation="Vertical"> <Ellipse Fill="Blue" Width="20" Height="20" HorizontalAlignment="Center" go:Node.LinkableFrom="True" go:Node.LinkableTo="True" Cursor="Arrow" go:Node.FromSpot="AllSides" go:Node.ToSpot="AllSides"/> <TextBlock x:Name="Text" Text="{Binding Path=Data.Key}" HorizontalAlignment="Center" /> </StackPanel> </Border> </DataTemplate>When the node is not selected, the background is a linear gradient brush. When the node is selected, the background is a solid DodgerBlue.
By default true converts to the system highlight color/brush (typically bluish) and false converts to the system highlight text color/brush (typically white).
System.Object
Northwoods.GoXam.Converter
Northwoods.GoXam.BooleanBrushConverter