, . Content . , , "True" "False", , 2 . Cnverter Tag , Name . , RouterEvents xaml.
public class TestConverter : IValueConverter
{
private string _originalValue = String.Empty;
private bool _previousValue = false;
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
_originalValue = (string)value;
_previousValue = !_previousValue;
return _previousValue.ToString();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return _originalValue;
}
}
:
label1.DataContext = new Test() { Name = DateTime.Now.ToString() };
XAML:
<Window.Resources>
<local:TestConverter x:Key="TestConverter" />
</Window.Resources>
<Grid>
<Label
Height="28"
HorizontalAlignment="Left"
Margin="132,96,0,0"
Name="label1" VerticalAlignment="Top" Width="120">
<Label.Content>
<Binding Path="Name"/>
</Label.Content>
<Label.Tag>
<Binding Path="Name" Converter="{StaticResource TestConverter}"/>
</Label.Tag>
<Label.Background>
<SolidColorBrush x:Name="animatedBrush1" Color="Yellow" />
</Label.Background>
<Label.Style>
<Style TargetType="Label">
<Style.Triggers>
<Trigger Property="Tag" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard AutoReverse="True">
<DoubleAnimation
Storyboard.TargetProperty="Opacity" To="0.0" AutoReverse="True"/>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
<Trigger Property="Tag" Value="False">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard AutoReverse="True">
<DoubleAnimation
Storyboard.TargetProperty="FontSize" To="20"/>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
</Style.Triggers>
</Style>
</Label.Style>
<Label.Triggers>
<EventTrigger RoutedEvent="Label.MouseEnter">
<BeginStoryboard>
<Storyboard>
<ColorAnimation
Storyboard.TargetName="animatedBrush1"
Storyboard.TargetProperty="Color"
To="Blue" Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="Label.MouseLeave">
<BeginStoryboard>
<Storyboard>
<ColorAnimation
Storyboard.TargetName="animatedBrush1"
Storyboard.TargetProperty="Color"
To="Yellow" Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Label.Triggers>
</Label>
</Grid>
, ,