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>
相关推荐
Macbethad2 天前
技术方案:工业控制系统架构设计
wpf
狮恒2 天前
OpenHarmony Flutter 分布式数据持久化:跨设备数据一致性与同步方案
分布式·flutter·wpf·openharmony
狮恒2 天前
OpenHarmony Flutter 分布式数据管理:跨设备数据同步与一致性保障方案
分布式·flutter·wpf·openharmony
Macbethad2 天前
工业设备IO模拟程序
wpf
狮恒2 天前
OpenHarmony Flutter 分布式设备发现与连接:无感组网与设备协同管理方案
分布式·flutter·wpf·openharmony
云和数据.ChenGuang2 天前
鸿蒙负一屏的技术定位与核心价值
华为·wpf·harmonyos
狮恒2 天前
OpenHarmony Flutter 分布式数据管理实战:全场景数据一致性与高效流转方案
wpf
狮恒2 天前
OpenHarmony Flutter 分布式音视频:跨设备流传输与实时协同交互方案
分布式·flutter·wpf·openharmony
狮恒3 天前
OpenHarmony Flutter 分布式安全与隐私保护:跨设备可信交互与数据防泄漏方案
分布式·flutter·wpf·openharmony
狮恒3 天前
OpenHarmony Flutter 分布式智能协同:基于 AI 的跨端场景感知与自适应交互方案
wpf