WPF---->自定义控件添加Popup弹出框

自定义控件,当点击自定义控件时弹出提示框

重要属性

属性名称解释使用方法
PlacementTarget安置目标Popup附着在那个控件上PlacementTarget="{Binding ElementName=TextBox1}"
IsOpen是否显示是否显示弹出框IsOpen="{Binding ElementName=TextBox1,Path=IsFocused, Mode=OneWay}"
PopupAnimation弹出动画显示窗口时是否使用动画,
只有在 AllowsTransparency 等于true时此属性才有用,设置一些Popup的弹出时的动画效果。
我们可以设置PopupAnimation=“Fade” 表示弹出时是通过渐入的方式进入的
PopupAnimation=“Fade” //透明度渐变显现
PopupAnimation=“None”//触发显示
PopupAnimation=“Scroll”//左上角滑出
PopupAnimation=“Slide”//从上面滑出
HorizontalOffset水平偏移量与附着控件水平偏移量
VerticalOffset垂直偏移量与附着控件的水平偏移量
Placement弹出位置设置弹出框相对于主体的位置Placement=“Top”
AllowsTransparency允许背景为透明
StaysOpen控制关闭false 窗口移动,工具提示或弹出窗口Popup就会消失

普通使用

	<Grid>
        <TextBox x:Name="TextBox1" Grid.Column="1"/>
        <Popup IsOpen="{Binding ElementName=TextBox1,Path=IsFocused, Mode=OneWay}" PlacementTarget="{Binding ElementName=TextBox1}"  Height="70" Width="210" PopupAnimation="Slide" HorizontalOffset="10">
            <Label Content="hahahha" Background="AliceBlue" VerticalAlignment="Center" HorizontalAlignment="Center" Height="70" Width="210"/>
        </Popup>
    </Grid>

自定义控件使用Popup

    <Style x:Key="PopBox" TargetType="{x:Type TextBox}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="TextBox">
                    <Grid>
                        <TextBox x:Name="TextBox1" Height="30" Width="120"/>
                        <Popup IsOpen="{Binding ElementName=TextBox1,Path=IsFocused, Mode=OneWay}" PlacementTarget="{Binding ElementName=TextBox1}" Grid.ColumnSpan="2"  Placement="Bottom" Height="60" Width="180">
                            <Label Height="60" Width=" 180" Background="AliceBlue" Content="{Binding ElementName=TextBox1,Path=Text}"/>
                        </Popup>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


参考文档

父窗口拖动的时候Popup不随着父窗口移动”问题的解决方案

让WPF的Popup不总置顶的解决方案

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值