当前位置: 首页 > news >正文

xceed PropertyGrid 如何做成Visual Studio 的属性窗口样子

类似这样的,我百度了一下,发现使用Xceed 不错。使用PropertyGrid

前台代码为

<Windowx:Class="WpfApp.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:local="clr-namespace:WpfApp"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"Title="PropertyGrid Event Example"Width="800"Height="450"d:DataContext="{d:DesignInstance Type=local:MainViewModel}"mc:Ignorable="d"><Window.Resources><!--  定义转换器  --><local:CommandItemToCommandConverter x:Key="CommandItemToCommandConverter" /><!--  定义模板  --><DataTemplate x:Key="EventEditTemplate"><StackPanel Orientation="Horizontal"><!--  下拉框选择命令  --><ComboBoxWidth="150"DisplayMemberPath="Name"ItemsSource="{Binding DataContext.ButtonViewModel.Commands, RelativeSource={RelativeSource AncestorType=Window}}"SelectedItem="{Binding DataContext.ButtonViewModel.EventClick, RelativeSource={RelativeSource AncestorType=Window}, Converter={StaticResource CommandItemToCommandConverter}, Mode=TwoWay}" /></StackPanel></DataTemplate></Window.Resources><StackPanel Orientation="Vertical"><!--  PropertyGrid that binds to the Button object  --><xctk:PropertyGrid Name="MyPropertyGrid" SelectedObject="{Binding ButtonViewModel}"><xctk:PropertyGrid.EditorDefinitions><xctk:EditorTemplateDefinition EditingTemplate="{StaticResource EventEditTemplate}" TargetProperties="EventClick" /></xctk:PropertyGrid.EditorDefinitions></xctk:PropertyGrid><ButtonWidth="100"Height="100"Command="{Binding ButtonViewModel.EventClick, NotifyOnSourceUpdated=True}"Content="sub" /></StackPanel>
</Window>

后台代码为

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
using System.IO;
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.Interactivity;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xaml;
using static WpfApp.ButtonViewModel;namespace WpfApp
{public partial class MainWindow : Window{public MainWindow(){InitializeComponent();DataContext = new MainViewModel(); // Set the DataContext to ViewModel}}public class MainViewModel{public ButtonViewModel ButtonViewModel { get; }public MainViewModel(){ButtonViewModel = new ButtonViewModel();}}public class CommandItemToCommandConverter : IValueConverter{public object Convert(object value, Type targetType, object parameter, CultureInfo culture){// 将 ICommand 转换回 CommandItemif (value is ICommand command){var viewModel = Application.Current.MainWindow.DataContext as ButtonViewModel;if (viewModel != null){return viewModel.Commands.FirstOrDefault(item => item.Command == command);}}return null;}public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture){// 从 CommandItem 提取 ICommandif (value is CommandItem commandItem){return commandItem.Command;}return null;}}public class CommandItem{public string Name { get; set; }public ICommand Command { get; set; }}public class ButtonViewModel : INotifyPropertyChanged{private ICommand _eventClick;public ObservableCollection<CommandItem> Commands { get; set; }public ICommand EventClick{get => _eventClick;set{_eventClick = value;OnPropertyChanged(nameof(EventClick));}}public ButtonViewModel(){Commands = new ObservableCollection<CommandItem>{new CommandItem{Name = "Say Hello",Command = new RelayCommand(_ => MessageBox.Show("Hello!"))},new CommandItem{Name = "Say Goodbye",Command = new RelayCommand(_ => MessageBox.Show("Goodbye!"))}};// 初始化默认命令EventClick = Commands.FirstOrDefault()?.Command;}public event PropertyChangedEventHandler PropertyChanged;protected void OnPropertyChanged(string propertyName){PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));}}public class RelayCommand : ICommand{private readonly Action<object> _execute;private readonly Predicate<object> _canExecute;public RelayCommand(Action<object> execute) : this(execute, null){ }public RelayCommand(Action<object> execute, Predicate<object> canExecute){_execute = execute ?? throw new ArgumentNullException(nameof(execute));_canExecute = canExecute;}public bool CanExecute(object parameter){return true;}public void Execute(object parameter){_execute(parameter);}public event EventHandler CanExecuteChanged{add { CommandManager.RequerySuggested += value; }remove { CommandManager.RequerySuggested -= value; }}}
}

这是一个完整可以运行的例子。其实要做成vs 那样的,路途很遥远,这里只是举个例子,需要重写很多模板,像前面的代码中就是定义了Event 选择的模板

 实际运行效果如下:

相关文章:

xceed PropertyGrid 如何做成Visual Studio 的属性窗口样子

类似这样的&#xff0c;我百度了一下&#xff0c;发现使用Xceed 不错。使用PropertyGrid 前台代码为 <Windowx:Class"WpfApp.MainWindow"xmlns"http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x"http://schemas.microsoft.co…...

Fork/Join框架_任务分解与并行执行

1 概述 Fork/Join框架是Java 7引入的一个用于并行执行任务的框架。它特别适用于可以递归分解为多个子任务的工作,每个子任务可以独立执行,并且结果可以合并以获得最终结果。Fork/Join框架通过工作窃取(work-stealing)算法提高了多核处理器上的任务执行效率。 2 核心组件 …...

智能家居监控系统数据收集积压优化

亮点&#xff1a;RocketMQ 消息大量积压问题的解决 假设我们正在开发一个智能家居监控系统。该系统从数百万个智能设备&#xff08;如温度传感器、安全摄像头、烟雾探测器等&#xff09;收集数据&#xff0c;并通过 RocketMQ 将这些数据传输到后端进行处理和分析。 在某些情况下…...

详解python的单例模式

单例模式是一种设计模式&#xff0c;它确保一个类只有一个实例&#xff0c;并提供一个全局访问点来获取这个实例。在Python中实现单例模式有多种方法&#xff0c;下面我将详细介绍几种常见的实现方式。 1. 使用模块 Python的模块天然就是单例的&#xff0c;因为模块在第一次导…...

momask-codes 部署踩坑笔记

目录 依赖项 t2m_nlayer8_nhead6_ld384_ff1024_cdp0.1_rvq6ns 推理代码完善&#xff1a; 代码地址&#xff1a; https://github.com/EricGuo5513/momask-codes 依赖项 pip install numpy1.23 matplotlib 必须指定版本&#xff1a;pip install matplotlib3.3.4 t2m_nlayer…...

H3CNE-31-BFD

Bidirectional Forwarding Dection&#xff0c;双向转发检查 作用&#xff1a;毫秒级故障检查&#xff0c;通常结合三层协议&#xff08;静态路由、vrrp、ospf、BGP等&#xff09;&#xff0c;实现链路故障快速检查。 BFD配置示例 没有中间的SW&#xff0c;接口down&#xff…...

蓝桥备赛指南(5)

queue队列 queue是一种先进先出的数据结构。它提供了一组函数来操作和访问元素&#xff0c;但它的功能相对较简单&#xff0c;queue函数的内部实现了底层容器来存储元素&#xff0c;并且只能通过特定的函数来访问和操作元素。 queue函数的常用函数 1.push()函数&#xff1a;…...

讯飞智作 AI 配音技术浅析(一)

一、核心技术 讯飞智作 AI 配音技术作为科大讯飞在人工智能领域的重要成果&#xff0c;融合了多项前沿技术&#xff0c;为用户提供了高质量的语音合成服务。其核心技术主要涵盖以下几个方面&#xff1a; 1. 深度学习与神经网络 讯飞智作 AI 配音技术以深度学习为核心驱动力&…...

MySQL(高级特性篇) 14 章——MySQL事务日志

事务有4种特性&#xff1a;原子性、一致性、隔离性和持久性 事务的隔离性由锁机制实现事务的原子性、一致性和持久性由事务的redo日志和undo日志来保证&#xff08;1&#xff09;REDO LOG称为重做日志&#xff0c;用来保证事务的持久性&#xff08;2&#xff09;UNDO LOG称为回…...

openRv1126 AI算法部署实战之——TensorFlow TFLite Pytorch ONNX等模型转换实战

Conda简介 查看当前系统的环境列表 conda env list base为基础环境 py3.6-rknn-1.7.3为模型转换环境&#xff0c;rknn-toolkit版本V1.7.3&#xff0c;python版本3.6 py3.6-tensorflow-2.5.0为tensorflow模型训练环境&#xff0c;tensorflow版本2.5.0&#xff0c;python版本…...

【Redis】常见面试题

什么是Redis&#xff1f; Redis 和 Memcached 有什么区别&#xff1f; 为什么用 Redis 作为 MySQL 的缓存&#xff1f; 主要是因为Redis具备高性能和高并发两种特性。 高性能&#xff1a;MySQL中数据是从磁盘读取的&#xff0c;而Redis是直接操作内存&#xff0c;速度相当快…...

每日 Java 面试题分享【第 17 天】

欢迎来到每日 Java 面试题分享栏目&#xff01; 订阅专栏&#xff0c;不错过每一天的练习 今日分享 3 道面试题目&#xff01; 评论区复述一遍印象更深刻噢~ 目录 问题一&#xff1a;Java 中的访问修饰符有哪些&#xff1f;问题二&#xff1a;Java 中静态方法和实例方法的区…...

「全网最细 + 实战源码案例」设计模式——桥接模式

核心思想 桥接模式&#xff08;Bridge Pattern&#xff09;是一种结构型设计模式&#xff0c;将抽象部分与其实现部分分离&#xff0c;使它们可以独立变化。降低代码耦合度&#xff0c;避免类爆炸&#xff0c;提高代码的可扩展性。 结构 1. Implementation&#xff08;实现类…...

JavaScript 进阶(上)

作用域 局部作用域 局部作用域分为函数作用域和块作用域。 函数作用域&#xff1a; 在函数内部声明的变量只能在函数内部被访问&#xff0c;外部无法直接访问。 总结&#xff1a; 函数内部声明的变量&#xff0c;在函数外部无法被访问 函数的参数也是函数内部的局部变量 …...

【编译原理实验二】——自动机实验:NFA转DFA并最小化

本篇适用于ZZU的编译原理课程实验二——自动机实验&#xff1a;NFA转DFA并最小化&#xff0c;包含了实验代码和实验报告的内容&#xff0c;读者可根据需要参考完成自己的程序设计。 如果是ZZU的学弟学妹看到这篇&#xff0c;那么恭喜你&#xff0c;你来对地方啦&#xff01; 如…...

深入探讨:服务器如何响应前端请求及后端如何查看前端提交的数据

深入探讨&#xff1a;服务器如何响应前端请求及后端如何查看前端提交的数据 一、服务器如何响应前端请求 前端与后端的交互主要通过 HTTP 协议实现。以下是详细步骤&#xff1a; 1. 前端发起 HTTP 请求 GET 请求&#xff1a;用于从服务器获取数据。POST 请求&#xff1a;用…...

如何利用Docker和.NET Core实现环境一致性、简化依赖管理、快速部署与扩展,同时提高资源利用率、确保安全性和生态系统支持

目录 1. 环境一致性 2. 简化依赖管理 3. 快速部署与扩展 4. 提高资源利用率 5. 确保安全性 6. 生态系统支持 总结 使用 Docker 和 .NET Core 结合&#xff0c;可以有效地实现环境一致性、简化依赖管理、快速部署与扩展&#xff0c;同时提高资源利用率、确保安全性和生态…...

@Inject @Qualifier @Named

Inject Qualifier Named 在依赖注入&#xff08;DI&#xff09;中&#xff0c;Inject、Qualifier 和 Named 是用于管理对象创建和绑定的关键注解。以下是它们的用途、依赖配置和代码示例的详细说明&#xff1a; 1. 注解的作用 Inject&#xff1a;标记需要注入的构造函数、字段…...

创建 priority_queue - 进阶(内置类型)c++

内置类型就是 C 提供的数据类型&#xff0c;⽐如 int 、 double 、 long long 等。以 int 类型为例&#xff0c;分 别创建⼤根堆和⼩根堆。 这种写法意思是&#xff0c;我要告诉这个优先级队列要建一个什么样的堆&#xff0c;第一个int是要存什么数据类型&#xff0c;vecto…...

2. Java-MarkDown文件解析-工具类

2. Java-MarkDown文件解析-工具类 1. 思路 读取markdown文件的内容&#xff0c;根据markdown的语法进行各个类型语法的解析。引入工具类 commonmark 和 commonmark-ext-gfm-tables进行markdown语法解析。 2. 工具类 pom.xml <!-- commonmark 解析markdown --> <d…...

RocketMQ延迟消息机制

两种延迟消息 RocketMQ中提供了两种延迟消息机制 指定固定的延迟级别 通过在Message中设定一个MessageDelayLevel参数&#xff0c;对应18个预设的延迟级别指定时间点的延迟级别 通过在Message中设定一个DeliverTimeMS指定一个Long类型表示的具体时间点。到了时间点后&#xf…...

鸿蒙中用HarmonyOS SDK应用服务 HarmonyOS5开发一个生活电费的缴纳和查询小程序

一、项目初始化与配置 1. 创建项目 ohpm init harmony/utility-payment-app 2. 配置权限 // module.json5 {"requestPermissions": [{"name": "ohos.permission.INTERNET"},{"name": "ohos.permission.GET_NETWORK_INFO"…...

Rapidio门铃消息FIFO溢出机制

关于RapidIO门铃消息FIFO的溢出机制及其与中断抖动的关系&#xff0c;以下是深入解析&#xff1a; 门铃FIFO溢出的本质 在RapidIO系统中&#xff0c;门铃消息FIFO是硬件控制器内部的缓冲区&#xff0c;用于临时存储接收到的门铃消息&#xff08;Doorbell Message&#xff09;。…...

《C++ 模板》

目录 函数模板 类模板 非类型模板参数 模板特化 函数模板特化 类模板的特化 模板&#xff0c;就像一个模具&#xff0c;里面可以将不同类型的材料做成一个形状&#xff0c;其分为函数模板和类模板。 函数模板 函数模板可以简化函数重载的代码。格式&#xff1a;templa…...

代码随想录刷题day30

1、零钱兑换II 给你一个整数数组 coins 表示不同面额的硬币&#xff0c;另给一个整数 amount 表示总金额。 请你计算并返回可以凑成总金额的硬币组合数。如果任何硬币组合都无法凑出总金额&#xff0c;返回 0 。 假设每一种面额的硬币有无限个。 题目数据保证结果符合 32 位带…...

go 里面的指针

指针 在 Go 中&#xff0c;指针&#xff08;pointer&#xff09;是一个变量的内存地址&#xff0c;就像 C 语言那样&#xff1a; a : 10 p : &a // p 是一个指向 a 的指针 fmt.Println(*p) // 输出 10&#xff0c;通过指针解引用• &a 表示获取变量 a 的地址 p 表示…...

Unity中的transform.up

2025年6月8日&#xff0c;周日下午 在Unity中&#xff0c;transform.up是Transform组件的一个属性&#xff0c;表示游戏对象在世界空间中的“上”方向&#xff08;Y轴正方向&#xff09;&#xff0c;且会随对象旋转动态变化。以下是关键点解析&#xff1a; 基本定义 transfor…...

深度解析:etcd 在 Milvus 向量数据库中的关键作用

目录 &#x1f680; 深度解析&#xff1a;etcd 在 Milvus 向量数据库中的关键作用 &#x1f4a1; 什么是 etcd&#xff1f; &#x1f9e0; Milvus 架构简介 &#x1f4e6; etcd 在 Milvus 中的核心作用 &#x1f527; 实际工作流程示意 ⚠️ 如果 etcd 出现问题会怎样&am…...

Angular中Webpack与ngx-build-plus 浅学

Webpack 在 Angular 中的概念 Webpack 是一个模块打包工具&#xff0c;用于将多个模块和资源打包成一个或多个文件。在 Angular 项目中&#xff0c;Webpack 负责将 TypeScript、HTML、CSS 等文件打包成浏览器可以理解的 JavaScript 文件。Angular CLI 默认使用 Webpack 进行项目…...

数据可视化交互

目录 【实验目的】 【实验原理】 【实验环境】 【实验步骤】 一、安装 pyecharts 二、下载数据 三、实验任务 实验 1&#xff1a;AQI 横向对比条形图 代码说明&#xff1a; 运行结果&#xff1a; 实验 2&#xff1a;AQI 等级分布饼图 实验 3&#xff1a;多城市 AQI…...