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>
相关推荐
就是有点傻1 天前
WPF按钮走马灯效果
wpf
zuozewei1 天前
虚拟电厂聚合商平台安全技术体系深度解读
安全·wpf
极客智造1 天前
WPF 自定义控件:AutoGrid 实现灵活自动布局的网格控件
wpf
极客智造1 天前
WPF Grid 布局高效扩展:GridHelpers 附加属性工具类全解析
wpf
张人玉1 天前
WPF 多语言实现完整笔记(.NET 4.7.2)
笔记·.net·wpf·多语言实现·多语言适配
暖馒1 天前
深度剖析串口通讯(232/485)
开发语言·c#·wpf·智能硬件
我要打打代码2 天前
WPF控件(2)
wpf
c#上位机2 天前
wpf之行为
c#·wpf
kylezhao20192 天前
深入浅出地理解 C# WPF 中的属性
hadoop·c#·wpf
全栈开发圈2 天前
干货分享|HarmonyOS核心技术理念
wpf·鸿蒙