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.

54 lines
2.3 KiB

<Window x:Class="PropertyTriggerSample.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:PropertyTriggerSample"
mc:Ignorable="d"
Title="MainWindow" Height="400" Width="400">
<Window.Resources>
<Style x:Key="styMain">
<Setter Property="Control.Foreground" Value="Red"/>
<Setter Property="TextBlock.Text" Value="Hello, WPF!"/>
<Style.Triggers>
<Trigger Property="Control.IsMouseOver" Value="True">
<Setter Property="Control.Foreground" Value="Blue"/>
<Setter Property="TextBlock.Text" Value="Enter the TextBlock"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock x:Name="tbMain" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center"
Text="Hello, WPF World!"
FontSize="30">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="Green"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="Red"/>
<Setter Property="TextDecorations" Value="Underline"/>
</Trigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
<StackPanel Orientation="Vertical" Grid.Row="1">
<Button VerticalAlignment="Center" HorizontalAlignment="Center"
Content="Button"
Style="{StaticResource styMain}"/>
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center"
Style="{StaticResource styMain}"/>
</StackPanel>
</Grid>
</Window>