We can change
the property of control based on another property using property triggers.The
below code is simple example of property trigger which display the text based
on checkbox.
<Window x:Class="WpfPropertyTriggers.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.Resources>
<!--Add
the style for check box-->
<Style TargetType="{x:Type CheckBox}" x:Key="cbStyle">
<Style.Triggers>
<!--Check whether checkbox checked or not-->
<Trigger Property="IsChecked" Value="true">
<!--If checkbox is checked then display the text and
set the color-->
<Setter Property="Foreground" Value="Red"></Setter>
<Setter Property="Content" Value="You
checked the box..."></Setter>
</Trigger>
</Style.Triggers>
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"></ColumnDefinition>
</Grid.ColumnDefinitions>
<!--Apply
the style resource for check box-->
<CheckBox Name="cb" Grid.Column="0" Style="{StaticResource cbStyle}"></CheckBox>
</Grid>
</Window>
Let me know, if you have any feedback. Mail me for source code. Enjoy reading my articles…
sekhartechblog@gmail.com
No comments:
Post a Comment