wpf 制作丝滑Flyout浮出侧边栏Demo (Mahapps UI框架)

在这里插入图片描述
Flyout 属性

  • CloseButtonVisibility: 设置为 Collapsed,意味着关闭按钮不可见。
  • TitleVisibility: 设置为 Collapsed,意味着标题不可见。
  • IsPinned: 设置为 True,意味着这个 Flyout 会固定住,不会自动关闭。
  • Opacity: 设置为 1,意味着完全不透明。
  • Position: 设置为 Right,意味着这个 Flyout 会出现在右侧。
  • Width: 设置为 auto,意味着宽度会根据内容自动调整。
  • Background: 背景色设置为 AliceBlue。
  • IsOpen: 设置为 False,意味着默认情况下这个 Flyout 是关闭的。
<controls:Flyout x:Class="ControlsTest.FloatingBox"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:ControlsTest"mc:Ignorable="d" xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls" CloseButtonVisibility="Collapsed" TitleVisibility="Collapsed" IsPinned="True" Opacity="1"Position="Right" Width="auto" Background="AliceBlue" IsOpen="False"><Grid><Grid.ColumnDefinitions><ColumnDefinition/><ColumnDefinition/></Grid.ColumnDefinitions><StackPanel Grid.Row="0"><Button Content="123" Width="50"/><Button Width="50" Content="345"/></StackPanel><StackPanel Grid.Column="1"><Button Content="123" Width="30" Height="50" Click="Button_Click_1"/></StackPanel></Grid>
</controls:Flyout>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;namespace ControlsTest
{/// <summary>/// FloatingBox.xaml 的交互逻辑/// </summary>public partial class FloatingBox{public FloatingBox(){InitializeComponent();}public static readonly DependencyProperty ButtonClickCommandProperty =DependencyProperty.Register("ButtonClickCommand", typeof(ICommand), typeof(FloatingBox), new PropertyMetadata(null));public ICommand ButtonClickCommand{get { return (ICommand)GetValue(ButtonClickCommandProperty); }set { SetValue(ButtonClickCommandProperty, value); }}private void Button_Click_1(object sender, RoutedEventArgs e){if (ButtonClickCommand != null && ButtonClickCommand.CanExecute(null)){ButtonClickCommand.Execute(null);}}}
}
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows;namespace ControlsTest
{public class BoolToCollapsedConverter : IValueConverter{public object Convert(object value, Type targetType, object parameter, CultureInfo culture){Visibility result = Visibility.Collapsed;if (value == null || value == DependencyProperty.UnsetValue){return result;}string para = parameter as string;if (string.IsNullOrWhiteSpace(para)) {result = (((bool)value) ? Visibility.Collapsed : Visibility.Visible);return result;}if (string.Equals(para, "reverse", StringComparison.OrdinalIgnoreCase)){result = ((!(bool)value) ? Visibility.Collapsed : Visibility.Visible);return result;}return result;}public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture){return value;}}
}
<Window x:Class="ControlsTest.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:ControlsTest"mc:Ignorable="d"Title="MainWindow" Height="450" Width="800"><Grid><Grid.RowDefinitions><RowDefinition Height="*"/><RowDefinition Height="*"/></Grid.RowDefinitions><StackPanel><Button Width="50"/></StackPanel><Grid Grid.Row="1"><Button Content="Open" Height="30" Width="50" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,20,40,0" Click="Button_Click" Visibility="{Binding FbisOpen,Converter={StaticResource BoolToCollapsed}}" Background="Red"/><local:FloatingBox IsOpen="{Binding FbisOpen,UpdateSourceTrigger=PropertyChanged}" Height="100" ButtonClickCommand="{Binding ButtonClickCommand}"/></Grid></Grid>
</Window>
using PropertyChanged;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;namespace ControlsTest
{/// <summary>/// Interaction logic for MainWindow.xaml/// </summary>[AddINotifyPropertyChangedInterface]public partial class MainWindow : Window{public MainWindow(){InitializeComponent();DataContext = this;ButtonClickCommand = new RelayCommand(OnButtonClick);}private void OnButtonClick(){FbisOpen = false;}private bool fbisOpen = true;public bool FbisOpen{get { return fbisOpen; }set { fbisOpen = value; }} public ICommand ButtonClickCommand { get; set; }private void Button_Click(object sender, RoutedEventArgs e){if(FbisOpen){FbisOpen = false;}else{FbisOpen = true;}}}public class RelayCommand : ICommand{private readonly Action _execute;private readonly Func<bool> _canExecute;public RelayCommand(Action execute, Func<bool> canExecute = null){_execute = execute ?? throw new ArgumentNullException(nameof(execute));_canExecute = canExecute;}public bool CanExecute(object parameter){return _canExecute == null || _canExecute();}public void Execute(object parameter){_execute();}public event EventHandler CanExecuteChanged{add { CommandManager.RequerySuggested += value; }remove { CommandManager.RequerySuggested -= value; }}}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/59487.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Redis常见面试题概览——针对实习面试

目录 1. Redis基础2. Redis数据类型3. Redis多机与分布式4. Redis事务5. Redis性能和优化6. Redis应用场景7. Redis三大生产问题8. Redis客户端和连接 以下是Redis常见面试题的概览&#xff1a; 1. Redis基础 什么是Redis&#xff1f;Redis与其他key-value存储有什么不同&…

MySQL记录锁、间隙锁、临键锁(Next-Key Locks)详解

行级锁&#xff0c;每次操作锁住对应的行数据。锁定粒度最小&#xff0c;发生锁冲突的概率最低&#xff0c;并发度最高。 应用在InnoDB存储引擎中。InnoDB的数据是基于索引组织的&#xff0c;行锁是通过对索引上的索引项加锁来实现的&#xff0c;而不是对记录加的锁。 对于行…

GeoSever发布图层(保姆姬)

发布服务的具体步骤。 1. 安装 GeoServer 下载 GeoServer 安装包&#xff1a;GeoServer 官网按照安装说明进行安装&#xff0c;可以选择 Windows、Linux 或其他平台。 2. 启动 GeoServer 启动 GeoServer 通常通过访问 http://localhost:8080/geoserver 进行。默认用户名和密…

Hugging Face 两种加载模型的方式有什么区别

在 Hugging Face 上&#xff0c;这两种加载模型的方式有一些关键区别&#xff0c;并会影响后续的使用。 方式 1&#xff1a;使用 pipeline 高层次 API from transformers import pipelinepipe pipeline("text-generation", model"defog/sqlcoder-70b-alpha&q…

【LeetCode】【算法】139. 单词拆分

LeetCode 139. 单词拆分 题目 给你一个字符串s和一个字符串列表wordDict作为字典。如果可以利用字典中出现的一个或多个单词拼接出s则返回true。 注意&#xff1a;不要求字典中出现的单词全部都使用&#xff0c;并且字典中的单词可以重复使用。 示例&#xff1a; 输入: s “…

在离线环境中使用sealos工具快速部署一套高可用的k8s服务集群

文章目录 项目基础信息工具版本测试环境 下载资源文件下载sealos二进制命令文件下载k8s安装镜像和组件资源下载docker离线安装包下载Docker Registry容器镜像 NFS共享配置coredns服务的DNS解析配置安装配置sealos、k8s服务安装sealos工具导入k8s及相关组件镜像安装 K8s 集群部署…

交易所开发:构建安全、高效、可靠的数字资产交易平台

随着数字资产的不断发展&#xff0c;数字货币交易所作为连接数字资产与现实世界的重要桥梁&#xff0c;逐渐成为全球金融市场的核心组成部分。无论是比特币、以太坊等主流加密货币&#xff0c;还是各种基于区块链的资产&#xff0c;都需要通过交易所进行交换和流通。因此&#…

了解分布式数据库系统中的CAP定理

在分布式数据库系统的设计和实现中&#xff0c;CAP定理是一个至关重要的概念。CAP定理&#xff0c;全称为一致性&#xff08;Consistency&#xff09;、可用性&#xff08;Availability&#xff09;和分区容忍性&#xff08;Partition tolerance&#xff09;定理&#xff0c;由…

RabbitMQ应用问题

1. 幂等性保障 1.1 介绍 幂等性是数学和计算机科学中某些运算的性质, 它们可以被多次应⽤, ⽽不会改变初始应⽤的结果. 在应⽤程序中, 幂等性就是指对⼀个系统进⾏重复调⽤(相同参数), 不论请求多少次, 这些请求对系统的影响都是相同的效果. ⽐如数据库的 select 操作. 不同…

HTB:Sense[WriteUP]

目录 连接至HTB服务器并启动靶机 1.What is the name of the webserver running on port 80 and 443 according to nmap? 使用nmap对靶机TCP端口进行开放扫描 2.What is the name of the application that presents a login screen on port 443? 使用浏览器访问靶机80端…

【LeetCode每日一题】——802.找到最终的安全状态

文章目录 一【题目类别】二【题目难度】三【题目编号】四【题目描述】五【题目示例】六【题目提示】七【解题思路】八【时空频度】九【代码实现】十【提交结果】 一【题目类别】 图 二【题目难度】 中等 三【题目编号】 802.找到最终的安全状态 四【题目描述】 有一个有…

stm32使用串口的轮询模式,实现数据的收发

------内容以b站博主keysking为原型&#xff0c;整理而来&#xff0c;用作个人学习记录。 首先在STM32CubeMX中配置 前期工作省略&#xff0c;只讲重点设置。 这里我配置的是USART2的模式。 会发现&#xff0c;PA2和PA3分别是TX与RX&#xff0c;在连接串口时需要TX对RX&…

C++上机实验|继承与派生编程练习

1.实验目的 (1) 掌握派生与继承的概念与使用方法 (2) 运用继承机制对现有的类进行重用。 (3) 掌握继承中的构造函数与析构函数的调用顺序, (4) 为派生类设计合适的构造函数初始化派生类。 (5) 深入理解继承与组合的区别。 2.实验内容 设计一个人员类 person 和一个日期类 da…

【MySQL】 运维篇—故障排除与性能调优:案例分析与故障排除练习

理论知识及概念介绍 1. 故障排除的重要性 无论是电商平台、社交网络还是企业管理系统&#xff0c;数据库的稳定性和性能直接影响到用户体验和业务运作。因此&#xff0c;及时发现并解决数据库故障是确保系统高可用性和可靠性的关键。 2. 应用场景 电商平台&#xff1a;在大促…

【STL_list 模拟】——打造属于自己的高效链表容器

一、list节点 ​ list是一个双向循环带头的链表&#xff0c;所以链表节点结构如下&#xff1a; template<class T>struct ListNode{T val;ListNode* next;ListNode* prve;ListNode(int x){val x;next prve this;}};二、list迭代器 2.1、list迭代器与vector迭代器区别…

冒泡排序、选择排序、计数排序、插入排序、快速排序、堆排序、归并排序JAVA实现

常见排序算法实现 冒泡排序、选择排序、计数排序、插入排序、快速排序、堆排序、归并排序JAVA实现 文章目录 常见排序算法实现冒泡排序选择排序计数排序插入排序快速排序堆排序归并排序 冒泡排序 冒泡排序算法&#xff0c;对给定的整数数组进行升序排序。冒泡排序是一种简单…

如何高效集成每刻与金蝶云星空的报销单数据

每刻报销单集成到金蝶云星空的技术实现 在企业日常运营中&#xff0c;费用报销和付款申请是两个至关重要的环节。为了提升数据处理效率和准确性&#xff0c;我们采用了轻易云数据集成平台&#xff0c;将每刻系统中的报销单数据无缝对接到金蝶云星空的付款申请单中。本案例将详…

陪玩app小程序开发案例源码核心功能介绍

‌陪玩系统‌是一种基于互联网技术的服务平台&#xff0c;旨在为用户提供游戏陪玩、语音聊天、社交互动等功能。陪玩系统通常包括以下几个核心功能&#xff1a; ‌游戏约单‌&#xff1a;用户可以通过陪玩系统发布游戏约单&#xff0c;寻找合适的陪玩伙伴一起进行游戏&#xf…

【题解】【排序】—— [NOIP2017 普及组] 图书管理员

【题解】【排序】—— [NOIP2017 普及组] 图书管理员 [NOIP2017 普及组] 图书管理员题目背景题目描述输入格式输出格式输入输出样例输入 #1输出 #1 提示 1.思路解析2.AC代码 [NOIP2017 普及组] 图书管理员 通往洛谷的传送门 题目背景 NOIP2017 普及组 T2 题目描述 图书馆中…

WPF+MVVM案例实战(十七)- 自定义字体图标按钮的封装与实现(ABC类)

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 1、案例效果1、按钮分类2、ABC类按钮实现1、文件创建2、字体图标资源3、自定义依赖属性4、按钮特效样式实现 3、按钮案例演示1、页面实现与文件创建2、依赖注入3 运…