首页 > 解决方案 > Popover 应在延迟 0.3 秒后打开(Popover 是从 Popup 派生的 WPF 自定义控件)

问题描述

我有一个 Popover 控件,其 IsOpen 在 2 个条件下设置为 true(当字符串属性具有值且 Ui 控件上的 IsMouse 为 true 时)。Popover 应在延迟 0.3 秒后打开。样本

<ContentControl Content="{Binding}"
                Background="Transparent"
                AutomationProperties.AutomationId="xyz.ssd">
    <ContentControl.Style>
        <Style TargetType="{x:Type ContentControl}">
            <Setter Property="FontSize" Value="15" />
            <Setter Property="ContentTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <Border x:Name="ertt">
                            <StackPanel x:Name="Grid1" MouseEnter="Image11_OnMouseEnter"
                                        MouseLeave="Image11_OnMouseLeave" MouseDown="Grid1_OnMouseDown">
                                <Image Height="60" Width="60" Source="{StaticResource SampleImage}"
           ToolTip="{Binding DataContext.SomeTextToDisplay , RelativeSource={RelativeSource Mode=FindAncestor, 
                    AncestorType=tlui:MainWindow} , Mode=TwoWay}"
           DocumentViewerBase.IsMasterPage="True" 
           x:Name="Image11" >

                                </Image>
                                <controls:Popover 
                      PlacementTarget="{Binding ElementName=Image11}"
                      Placement="Bottom" Height="1" Width="1"
                      FocusManager.IsFocusScope="False"
                      controls:DialogWindowCloseBehavior.IsCloseButton="False"
                      AllowDrop="False"
                      AutomationProperties.IsOffscreenBehavior="FromClip"
                      controls:BackgroundBlurBehavior.BackgroundBlur="True"
                      controls:CultureBehavior.UseHarmonizedCulture="False"
                      ArrowHeight="1"
                   StaysOpen="True"
                      x:Name="SomePopover" 
        >
                                    <!--<controls:Popover.IsOpen>
                                        <MultiBinding Converter="{StaticResource BooleanToVisibilityConverter}">
                                            <Binding Path="DataContext.SomeTextToDisplay"
                                 RelativeSource="{RelativeSource Mode=FindAncestor, 
                                                                AncestorType=tlui:MainWindow}"  />
                                            <Binding Path="IsPopOverOpen"  RelativeSource="{RelativeSource AncestorType=conv:UserControl1}"
                        />
                                        </MultiBinding>
                                    </controls:Popover.IsOpen>-->
                                    <controls:Popover.IsHitTestVisible>False</controls:Popover.IsHitTestVisible>
                                    <controls:Popover.IsManipulationEnabled>False</controls:Popover.IsManipulationEnabled>
                                    <controls:Popover.VerticalOffset>-1</controls:Popover.VerticalOffset>
                                    <Border Margin="10,0,0,0" ClipToBounds="True">
                                        <Border.Resources>
                                            <Style TargetType="{x:Type Border}">
                                                <Setter Property="Width" Value="60" />
                                                <Setter Property="Height" Value="60" />
                                                <Setter Property="VerticalAlignment" Value="Center" />
                                                <Setter Property="HorizontalAlignment" Value="Center" />
                                            </Style>
                                        </Border.Resources>
                                        <StackPanel>
                                            <TextBlock x:Name="NotesComment"
                           TextWrapping="Wrap">
                                                <TextBlock.Text>
                                                    <Binding Path="DataContext.SomeTextToDisplay"
                                 RelativeSource="{RelativeSource Mode=FindAncestor, 
                                                                AncestorType=tlui:MainWindow}" />
                                                </TextBlock.Text>
                                            </TextBlock>
                                        </StackPanel>
                                    </Border>

                                </controls:Popover>
                            </StackPanel>
                        </Border>
                        <DataTemplate.Resources>
                            <Storyboard x:Key="OpenPopOver">
                                <BooleanAnimationUsingKeyFrames
                                    Storyboard.TargetName="SomePopover"
                                    Storyboard.TargetProperty="IsOpen"
                                    FillBehavior="Stop">
                                    <DiscreteBooleanKeyFrame KeyTime="0:0:2.3" Value="False"/>
                                </BooleanAnimationUsingKeyFrames>
                            </Storyboard>
                        </DataTemplate.Resources>
                        <DataTemplate.Triggers>
                            <Trigger SourceName="ertt" Property="IsMouseOver" Value="True">
                                <Trigger.EnterActions>
                                    <BeginStoryboard x:Name="bsb"  >
                                        <Storyboard>
                                            <BooleanAnimationUsingKeyFrames
                                                Storyboard.TargetName="SomePopover"
                                                Storyboard.TargetProperty="IsOpen"
                                                FillBehavior="HoldEnd">
                                                <DiscreteBooleanKeyFrame KeyTime="0:0:1.3" 
                                                                         Value="{Binding ElementName=Image11 ,Path=ToolTip,
                                                                Converter={x:Static converter:StringtoBool.Instance}}"/>
                                            </BooleanAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </Trigger.EnterActions>
                                <Trigger.ExitActions>
                                    <StopStoryboard BeginStoryboardName="bsb"/>
                                    <BeginStoryboard x:Name="bxb" Storyboard="{StaticResource OpenPopOver}"/>
                                </Trigger.ExitActions>
                            </Trigger>
                            <Trigger SourceName="SomePopover" Property="IsMouseOver" Value="True">

                                <Trigger.EnterActions>
                                    <StopStoryboard BeginStoryboardName="bsb"/>
                                </Trigger.EnterActions>
                                <!--<Trigger.ExitActions>
                                    <BeginStoryboard Storyboard="{StaticResource OpenPopOver}"/>
                                    <RemoveStoryboard BeginStoryboardName="bxb"/>
                                </Trigger.ExitActions>-->
                            </Trigger>
                        </DataTemplate.Triggers>
                    </DataTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </ContentControl.Style>
</ContentControl>

问题是每当我将鼠标悬停在 contentcontrol 上时,就会显示弹出框。它应该仅在 ContentControl 上的 Both IsMouseOver 为 tru 且图像(Image11)具有显示描述的工具提示时显示。图像在某些情况下不可见。在这些情况下,Popover 不应在将鼠标悬停在 contentcontrol 上时打开

标签: wpfxamlmvvmstoryboard

解决方案


推荐阅读