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>
相关推荐
yanaiding1 天前
C# WPF 独立开发看图工具 PixSight 经验介绍(二)—— 水印模块开发实录
图像处理·c#·wpf·个人开发
我是苏苏4 天前
WPF开发01:基础控件及常用模板篇
开发语言·c#·html·wpf
dalong105 天前
WPF:3D顶点共享与法线设置对光照效果的影响
3d·wpf
柔蘭5 天前
WPF中的CommunityToolkit.Mvvm框架
wpf
aGdF8E3gQ6 天前
【Application Insights】采样率对Function App日志收集的影响和解决方法
python·flask·wpf
程序员-Benothing6 天前
如何实现高并发系统订单30分钟自动关闭?
开发语言·c#·wpf
一水7 天前
Redis实战:一个AI工作流系统里的五个应用场景,从传参到限流的完整链路
数据库·redis·wpf
dalong107 天前
WPF:3D甜甜圈
3d·c#·wpf·甜甜圈
别催小唐敲代码7 天前
ROS2从入门到实战:去中心化机器人操作系统详解
wpf·ros2
脚踏实地皮皮晨8 天前
003006001_WrapPanel控件
开发语言·c#·.net·wpf·visual studio