我正在尝试使用弹出窗口上的样式,当它的父母被鼠标悬停时触发它。此外,我希望包含延迟,因为给定的控件可能被其他控件包围,其中包括自己的弹出窗口。
我也试图让我的应用程序遵循MVVM格式。
弹出代码:
<Popup Style="{StaticResource PopUpStyle}">
<Border Style="{StaticResource BorderStyle}"
Background="White"
Margin="4">
<HeaderedContentControl x:Name="hcc_Fields"
Style="{StaticResource HCCStyleLP}"
Header="{Binding Path=DisplayName}">
<ContentControl Style="{StaticResource ContentControlStyle}"
Content="{Binding Path=Controls}"
ContentTemplate="{StaticResource AreaTemplate}"
/>
</HeaderedContentControl>
</Border>
</Popup>
如您所见,我正在尝试在内容控件中绑定弹出窗口的内容。
弹出窗口本身显示正常,但只发生一次。 (请注意,这是我第一次使用触发器)
样式代码:
<Style x:Key="PopUpStyle" TargetType="{x:Type Popup}">
<Setter Property="AllowsTransparency" Value="True" />
<Setter Property="PopupAnimation" Value="Fade" />
<Setter Property="Placement" Value="MousePoint" />
<Setter Property="VerticalOffset" Value="-3" />
<Setter Property="HorizontalOffset" Value="-3" />
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=IsMouseOver}" Value="True">
<!--<Setter Property="IsOpen" Value="True" />-->
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="IsOpen" FillBehavior="HoldEnd">
<DiscreteBooleanKeyFrame Value="True" KeyTime="0:0:1" />
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="IsOpen" FillBehavior="HoldEnd">
<!--<DiscreteBooleanKeyFrame Value="False" KeyTime="0:0:1" />-->
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
</DataTrigger>
<Trigger Property="IsMouseOver" Value="True">
<!--<Setter Property="IsOpen" Value="True" />-->
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="IsOpen" FillBehavior="HoldEnd">
<DiscreteBooleanKeyFrame Value="True" KeyTime="0:0:0" />
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="IsOpen" FillBehavior="HoldEnd">
<DiscreteBooleanKeyFrame Value="False" KeyTime="0:0:1" />
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
</Style.Triggers>
</Style>
如果我删除了故事板:
<Style x:Key="PopUpStyle" TargetType="{x:Type Popup}">
<Setter Property="AllowsTransparency" Value="True" />
<Setter Property="PopupAnimation" Value="Fade" />
<Setter Property="Placement" Value="MousePoint" />
<Setter Property="VerticalOffset" Value="-3" />
<Setter Property="HorizontalOffset" Value="-3" />
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=IsMouseOver}" Value="True">
<Setter Property="IsOpen" Value="True" />
</DataTrigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="IsOpen" Value="True" />
</Trigger>
</Style>
弹出窗口不会卡住,可以使用子控件;但是,这不包括延迟,这可能使您将鼠标移动到您打算与之交互的控件。删除触发器上的故事板(但不是绑定的DataTrigger)似乎也有类似的效果。
我一直试图找到过去几天的答案,但是大多数实现使用后面的代码,或命名引用,这违背了我的应用程序。
感谢任何帮助, 感谢。