我正在为自定义Datepicker添加触发器以触发弹出文本块。
但是,当我运行代码时,我得到一个未处理的nullreferenceexception。
如果我删除触发器,一切正常。
<Grid.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Popup_PrevButton" Property="IsOpen" Value="True" />
<Setter TargetName="Popup_NextButton" Property="IsOpen" Value="True" />
</Trigger>
<Trigger Property="IsMouseOver" Value="False">
<Setter TargetName="Popup_PrevButton" Property="IsOpen" Value="False" />
<Setter TargetName="Popup_NextButton" Property="IsOpen" Value="False" />
</Trigger>
</Grid.Triggers>
我尝试将触发器放在PART_Button和ControlTemplate中但没有任何作用。
弹出代码紧跟在PART_Popup之后,如下所示:
<Popup x:Name="Popup_PrevButton"
PlacementTarget="{Binding ElementName=PART_Button}"
IsOpen="False"
Placement="Left"
StaysOpen="False"
AllowsTransparency="True"
PopupAnimation="Fade"
Focusable="True">
<StackPanel>
<Border Background="LightYellow">
<TextBlock>Show Custom Rext</TextBlock>
</Border>
</StackPanel>
</Popup>
什么是错误?
答案 0 :(得分:1)
元素的触发器仅支持EventTrigger
,因此您无法使用属性触发器(Trigger
)。看FrameworkElement.Triggers
Property。
<Grid.Triggers>
<EventTrigger RoutedEvent="UIElement.MouseEnter">
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames
Storyboard.TargetName="Popup_PrevButton"
Storyboard.TargetProperty="IsOpen">
<DiscreteBooleanKeyFrame KeyTime="00:00:00" Value="True"/>
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Grid.Triggers>