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>
相关推荐
Chris _data14 天前
WPF 学习第三天 — Modbus RTU 串口通信
hadoop·学习·wpf
布吉岛的石头14 天前
Java 程序员第 43 阶段05:微服务整合大模型,跨服务调用架构设计实战,Seata分布式事务实战
wpf
步步为营DotNet14 天前
基于.NET Aspire 实现云原生应用的高效监控与可观测性
云原生·.net·wpf
芒鸽15 天前
HarmonyOS 分布式开发实战:设备协同、数据共享与跨设备迁移
分布式·wpf·harmonyos
Volunteer Technology15 天前
Flink状态管理与容错(二)
大数据·flink·wpf
happyprince16 天前
07_verl-Trainer模块详解
人工智能·架构·wpf·强化学习
bugcome_com16 天前
WPF + Prism 技术指南与实战项目(二、模板搭建)
wpf
小满Autumn16 天前
log4net 日志框架 — 从配置到实战速查手册
笔记·c#·.net·wpf·上位机·log4net
政沅同学17 天前
基于 C# WPF + HALCON 的工业视觉算法工具框架(开源)
开发语言·c#·wpf
happyprince17 天前
03_verl-设计理念与核心原理
wpf