带弹出按钮

时间:2016-04-13 19:55:23

标签: c# wpf mvvm popup caliburn.micro

我有一个按钮,当用户将鼠标放在我要显示弹出窗口的元素上时。 在此弹出窗口内,包含用户可以单击的按钮。 所有这些都在Itemscontrol中。

当用户将鼠标悬停在按钮上时,我已经显示了弹出窗口,但我不知道如何:

1)如果用户没有"焦点"则隐藏弹出窗口在弹出窗口上。

2)如果用户专注于弹出窗口,在关注按钮后,弹出窗口必须保持打开状态

我的代码现在:

 <Button x:Name="MyButton" MouseEnter="LabelShift_MouseDown"  Background="{x:Null}" BorderBrush="{x:Null}" Style="{DynamicResource SquareButtonStyle}" >
        <Grid MaxHeight="80">
            <Grid.RowDefinitions>
                <RowDefinition Height="3*"/>
                <RowDefinition Height="2*"/>
            </Grid.RowDefinitions>
            <Viewbox Grid.Row="0" >
                <TextBlock Name="Identifier" FontSize="26" Margin="10,10,10,10" Foreground="White" Text="{Binding Identifier}"/>
            </Viewbox>
            <Viewbox Grid.Row="1"  VerticalAlignment="Bottom">
                <TextBlock Name="Value" FontSize="24" Margin="10,10,10,10" Foreground="White" Text="{Binding Total, StringFormat='C'}"/>
            </Viewbox>
        </Grid>
        <Button.Triggers>
            <EventTrigger RoutedEvent="MouseEnter">

                <BeginStoryboard>
                    <Storyboard>
                        <BooleanAnimationUsingKeyFrames
                                    Storyboard.TargetName="ToolTip"
                                    Storyboard.TargetProperty="IsOpen">
                            <DiscreteBooleanKeyFrame
                                        KeyTime="00:00:00"
                                        Value="True" />
                        </BooleanAnimationUsingKeyFrames>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
            <EventTrigger RoutedEvent="MouseLeave">

                <BeginStoryboard>
                    <Storyboard>
                        <BooleanAnimationUsingKeyFrames
                                    Storyboard.TargetName="ToolTip"
                                    Storyboard.TargetProperty="IsOpen">
                            <DiscreteBooleanKeyFrame
                                        KeyTime="00:00:00"
                                        Value="False" />
                        </BooleanAnimationUsingKeyFrames>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>

        </Button.Triggers>
    </Button>


<Popup x:Name="ToolTip" PlacementTarget="{Binding ElementName=MyButton}"  StaysOpen="True" Placement="Bottom" Height="Auto" Width="{Binding ActualWidth, ElementName=MyButton}" AllowsTransparency="True">
    <Grid>
        <Border BorderBrush="#909090" BorderThickness="1" CornerRadius="1" >
            <StackPanel Margin="10">
                <!-- Content/Elements-->
            </StackPanel>
        </Border>
    </Grid>
<Popup.Triggers>
    <EventTrigger RoutedEvent="MouseEnter">

        <BeginStoryboard>
            <Storyboard>
                <BooleanAnimationUsingKeyFrames
                                                                    Storyboard.TargetName="ToolTip"
                                                                    Storyboard.TargetProperty="IsOpen">
                    <DiscreteBooleanKeyFrame
                                                                        KeyTime="00:00:00"
                                                                        Value="True" />
                </BooleanAnimationUsingKeyFrames>
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger>

</Popup.Triggers>

0 个答案:

没有答案