You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
3.0 KiB

<Window x:Class="DataTriggerSample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:DataTriggerSample"
mc:Ignorable="d"
Title="MainWindow" Height="400" Width="400">
<Window.Resources>
<Style x:Key="styTextBlock" TargetType="TextBlock">
<Setter Property="Visibility" Value="Visible"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=cboMain, Path=IsChecked}" Value="True">
<Setter Property="Visibility" Value="Hidden"/>
</DataTrigger>
</Style.Triggers>
</Style>
<Style x:Key="styProgressBar" TargetType="ProgressBar">
<Setter Property="Foreground" Value="Green"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=pbMain, Path=Value}" Value="100">
<Setter Property="Foreground" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<CheckBox x:Name="cboMain" Content="Click me!" FontSize="20"/>
<TextBlock Text="Hello WFP!" FontSize="20"
Style="{StaticResource styTextBlock}"/>
</StackPanel>
<StackPanel Grid.Row="1">
<Slider x:Name="sldMain" Margin="10"
Minimum="0" Maximum="100"/>
<ProgressBar x:Name="pbMain" Height="10" Margin="10"
Minimum="0" Maximum="100"
Value="{Binding ElementName=sldMain, Path=Value}"
Style="{StaticResource styProgressBar}"/>
<TextBlock HorizontalAlignment="Center"
Text="{Binding ElementName=sldMain, Path=Value}"/>
<ProgressBar x:Name="pbSub" Height="30" Margin="10"
Minimum="0" Maximum="100"
Value="{Binding ElementName=sldMain, Path=Value}">
<ProgressBar.Style>
<Style TargetType="ProgressBar">
<Setter Property="Foreground" Value="Blue"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=pbMain, Path=Value}" Value="100">
<Setter Property="Foreground" Value="MediumPurple"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ProgressBar.Style>
</ProgressBar>
</StackPanel>
</Grid>
</Window>