嘿,我在我的项目中创建了一个用户控件。我想当它的 Visibility 属性改变时,运行一行代码
VisualStateManager.GoToState(this, "Normal", true);
此属性绑定到数据源。
<usercontrol:CorrectAnswerMessage Grid.Column="1" x:Name="correct"
Visibility="{Binding IsTrueAnswer,Mode=TwoWay}" VerticalAlignment="Center"
HorizontalAlignment="Left"></usercontrol:CorrectAnswerMessage>
我正在寻找一种为 Visibility 属性创建事件的方法。当这个属性改变时,事件被触发。
这是我的用户控件
<UserControl
x:Class="Lifener.UserControls.CorrectAnswerMessage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Lifener.UserControls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="500">
<Grid x:Name="CorrectResult" Width="400" Height="350" Visibility="Visible" HorizontalAlignment="Center" Margin="0">
<TextBlock Text="" FontSize="120" FontFamily="Segoe UI Symbol" Padding="0" Margin="0" VerticalAlignment="Center" HorizontalAlignment="Center" />
<TextBlock TextAlignment="Center" Text="" FontSize="60" FontFamily="Segoe UI Symbol" Margin="130,30,55,215" />
<TextBlock x:Name="Like" TextAlignment="Center" Text="" FontSize="60" FontFamily="Segoe UI Symbol" Margin="165,30,20,0" Foreground="Green" RenderTransformOrigin="0.5,0.5" Height="104" VerticalAlignment="Top"/>
<TextBlock x:Uid="AnswerIsRight" HorizontalAlignment="Left" Margin="185,140,0,0" TextWrapping="Wrap" Text="Hooora, Right. You are awsome." VerticalAlignment="Top" Width="185" Height="140" TextAlignment="Center" FontSize="28" FontWeight="Bold"/>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonGroups">
<VisualState x:Name="Normal" >
<VisualState.Storyboard>
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Like"
Storyboard.TargetProperty="Foreground"
Duration="0:0:2.5"
AutoReverse="True"
RepeatBehavior="Forever">
<DiscreteObjectKeyFrame Value="Red" KeyTime="0"></DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState.Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>