WPF 弹出窗体Popup

在一个文件管理项目中需要做一个收藏夹时,如果用普通的Window时需要处理点按钮弹出,点无关的地方再自动关闭。也可以做就是比较麻烦。WPF自带提供了一种弹出窗体Popup。可以很方便实现这些功能。

XML 复制代码
 <ToggleButton Style="{StaticResource ToggleImageStyle}"
         zhao:IconElement.Width="20" 
         zhao:IconElement.Height="20"
         zhao:IconElement.Image="{StaticResource 收藏}"
         Command="{Binding Ok2Command}">
  <Popup VerticalOffset="2" Focusable="False" StaysOpen="False"
         AllowsTransparency="True" PopupAnimation="Slide"
         MinWidth="200" MaxWidth="400" MinHeight="100" MaxHeight="600"
         Placement="Bottom"  PlacementTarget="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ToggleButton}}"
         IsOpen="{Binding IsChecked, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ToggleButton}}">
   <Border Background="White" BorderBrush="Gray"  BorderThickness="1.5" CornerRadius="5" Margin="10">
    <Border.Effect>
     <DropShadowEffect Color="Gray" ShadowDepth="3" BlurRadius="5" Opacity="0.3"/>
    </Border.Effect>
    <Grid Margin="3">
     <TextBlock Text="我是一个Popup" HorizontalAlignment="Center" VerticalAlignment="Center"/>
    </Grid>
   </Border>
  </Popup>
 </ToggleButton>
相关推荐
Macbethad3 小时前
使用WPF编写一个MODBUSTCP通信的程序
wpf
unicrom_深圳市由你创科技3 小时前
Avalonia.WPF 跨平台图表的使用
wpf
-大头.14 小时前
深入解析ZooKeeper核心机制
分布式·zookeeper·wpf
Macbethad14 小时前
使用WPF编写一个RS232主站程序
wpf
Macbethad14 小时前
使用WPF编写一个485通信主站程序
wpf
忧思幽释1 天前
Mariadb Galera集群在Openstack中的应用
wpf·openstack·mariadb
张人玉1 天前
C#WPF——MVVM框架编写管理系统所遇到的问题
开发语言·c#·wpf·mvvm框架
Aevget2 天前
界面控件DevExpress WPF v25.1新版亮点:PDF Viewer功能全新升级
pdf·wpf·界面控件·devexpress·ui开发
5***a9753 天前
后端配置中心选型,Nacos与Apollo
wpf