关于WPF中Popup中的一些用法的总结

1.常用属性说明

IsOpen: 布尔值,指示 Popup 控件是否显示

StaysOpen: 布尔值,指示在 Popup 控件失去焦点的时候,是否关闭 Popup 控件的显示

PopupAnimation:指示显示窗口时是否使用动画,只有在 AllowsTransparency 等于true时此属性才有用,设置一些Popup的弹出时的动画效果。我们可以设置PopupAnimation="Fade" 表示弹出时是通过渐入的方式进入的

Popup 窗口本身是一个不可见的元素,只有在窗口上放置了信息后才能显示
Popup的定位方式与一般控件的定位方法不一样, Popup 使用五个属性来设定位置信息:
PlacementTarget:设定 Popup 定义所相对的控件,PlacementTarget="{Binding ElementName= '控件的名字'}"

如果没有为属性为 NULL,则 Popup 定位相对于屏幕的左上角

Placement:一个枚举值,指定 Popup 控件的定位方式

PlacementRectangle:设定一个矩形,在 Popup 控件显示时,位置将相对于此矩形来显示,此矩形的位置也相对于PlacementTarget 属性所设定的控件
HorizontalOffset:指定一个值,指示 Popup 的位置所需水平移动多少个象素
VerticalOffset:指定一个值,指示 Popup 的位置所需垂直移动多少个象素

    <Style TargetType="Button" x:Key="btnButtonPopupStyle">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Border x:Name="Item" BorderThickness="1" Cursor="Hand" Background="{DynamicResource Background-Info1}" CornerRadius="0,0,0,0">
                        <DockPanel VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5">
                            <Viewport3D Grid.Column="0" Width="30" Height="30" Margin="0,0,0,0">
                                <Viewport3D.Camera>
                                    <PerspectiveCamera Position="0 0 700" LookDirection="0 0 -1" />
                                </Viewport3D.Camera>
                                <Viewport3D.Children>
                                    <ContainerUIElement3D>
                                        <Viewport2DVisual3D>
                                            <Viewport2DVisual3D.Geometry>
                                                <MeshGeometry3D Positions="-200 200 0  -200 -200 0  200 -200 0  200 200 0" TriangleIndices="0 1 2  0 2 3" TextureCoordinates="0 0  0 1  1 1  1 0"/>
                                            </Viewport2DVisual3D.Geometry>
                                            <Viewport2DVisual3D.Material>
                                                <DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True"/>
                                            </Viewport2DVisual3D.Material>
                                            <Viewport2DVisual3D.Visual>
                                                <Border Grid.Column="1" >
                                                    <TextBlock Style="{StaticResource HSFontAweSome}" Foreground="#fff" Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Content}" Margin="10" VerticalAlignment="Center"></TextBlock>
                                                </Border>
                                            </Viewport2DVisual3D.Visual>
                                        </Viewport2DVisual3D>
                                        <Viewport2DVisual3D>
                                            <Viewport2DVisual3D.Geometry>
                                                <MeshGeometry3D Positions="200 200 0  200 -200 0  -200 -200 0  -200 200 0" TriangleIndices="0 1 2  0 2 3" TextureCoordinates="0 0  0 1  1 1  1 0"/>
                                            </Viewport2DVisual3D.Geometry>
                                            <Viewport2DVisual3D.Material>
                                                <DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True"/>
                                            </Viewport2DVisual3D.Material>
                                            <Viewport2DVisual3D.Visual>
                                                <Border Grid.Column="1">
                                                    <TextBlock Style="{StaticResource HSFontAweSome}" Foreground="#fff" Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Content}" Margin="10" VerticalAlignment="Center"></TextBlock>
                                                </Border>
                                            </Viewport2DVisual3D.Visual>
                                        </Viewport2DVisual3D>
                                        <ContainerUIElement3D.Transform>
                                            <RotateTransform3D>
                                                <RotateTransform3D.Rotation>
                                                    <AxisAngleRotation3D x:Name="Rotation3D" Angle="0" Axis="0 1 0"/>
                                                </RotateTransform3D.Rotation>
                                            </RotateTransform3D>
                                        </ContainerUIElement3D.Transform>
                                    </ContainerUIElement3D>
                                    <ModelVisual3D>
                                        <ModelVisual3D.Content>
                                            <DirectionalLight Color="Transparent"/>
                                        </ModelVisual3D.Content>
                                    </ModelVisual3D>
                                </Viewport3D.Children>
                            </Viewport3D>
                            <TextBlock x:Name="ItemLabel" Foreground="#fff" Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Tag}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,10,0"/>
                            <TextBlock Style="{StaticResource HSFontAweSome}" Margin="0,-5,0,0" Foreground="#fff" Text="&#xf0dd;" FontSize="{DynamicResource DefaultFontSize}"></TextBlock>
                            <Popup x:Name="popShow"
                               IsOpen="False" StaysOpen="False"
                               PopupAnimation="Slide" AllowsTransparency="True"
                               PlacementTarget="{Binding ElementName= Item}"
                               Placement="Bottom">
                                <StackPanel>
                                    <Button Content="&#xf08e;" Tag="导入Execl" Style="{DynamicResource btnButtonStyle_Export}" Command="{Binding SimpleInteractionCommand}" CommandParameter="Execl"></Button>
                                    <Button Content="&#xf045;" Tag="导出Xml" Style="{DynamicResource btnButtonStyle_Export}"  Command="{Binding SimpleInteractionCommand}" CommandParameter="Xml"></Button>
                                </StackPanel>
                            </Popup>
                        </DockPanel>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="Item" Property="Background" Value="#00a3d2" />
                            <Setter TargetName="ItemLabel" Property="Foreground" Value="#fff" />
                            <Setter TargetName="popShow" Property="IsOpen" Value="true"/>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="false">
                            <Setter TargetName="popShow" Property="IsOpen" Value="false"/>
                        </Trigger>
                        <EventTrigger RoutedEvent="Mouse.MouseEnter">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="Rotation3D" Storyboard.TargetProperty="Angle" To="180" Duration="0:0:0.3"/>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                        <EventTrigger RoutedEvent="Mouse.MouseLeave">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="Rotation3D" Storyboard.TargetProperty="Angle" To="0" Duration="0:0:0.3"/>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
View Code

 

转载于:https://www.cnblogs.com/Li-JiaWen/p/11317299.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值