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

以橙色为主的网站网站建设硬件设置

以橙色为主的网站,网站建设硬件设置,做暖暖视频网站大全,网站建设 广州佛山💡WPF 项目实战:构建一个可增删、排序的光源类型管理界面(含源码) 在实际的图像处理项目中,我们经常需要对“光源类型”进行筛选或管理。今天我们来一步步构建一个实用的 WPF 界面,实现以下功能&#xff1…

💡WPF 项目实战:构建一个可增删、排序的光源类型管理界面(含源码)

在实际的图像处理项目中,我们经常需要对“光源类型”进行筛选或管理。今天我们来一步步构建一个实用的 WPF 界面,实现以下功能:

  • ✅ 添加新的光源类型
  • ❌ 删除已有光源类型
  • 🔼🔽 调整光源类型显示顺序
  • 🧠 使用标准的 MVVM 模式 + Prism 命令绑定

🏗️ 第一步:定义模型类

我们为每个光源项定义一个类 LightSourceFilterItem,它包含两个属性:光源名称、是否勾选。

public class LightSourceFilterItem : BindableBase
{public string Name { get; }private bool _isChecked;public bool IsChecked{get => _isChecked;set => SetProperty(ref _isChecked, value);}public LightSourceFilterItem(string name){Name = name;IsChecked = true;}
}

🧠 第二步:ViewModel 实现逻辑

ViewModel 是整个逻辑核心,包括添加、删除、排序命令。

public class LightTypeViewModel : BindableBase
{public ObservableCollection<LightSourceFilterItem> LightSourceItems { get; } = new();private string _newLightSourceName;public string NewLightSourceName{get => _newLightSourceName;set => SetProperty(ref _newLightSourceName, value);}public DelegateCommand AddLightSourceCommand { get; }public DelegateCommand<LightSourceFilterItem> RemoveLightSourceCommand { get; }public DelegateCommand<LightSourceFilterItem> MoveUpCommand { get; }public DelegateCommand<LightSourceFilterItem> MoveDownCommand { get; }public LightTypeViewModel(){AddLightSourceCommand = new DelegateCommand(AddLightSource);RemoveLightSourceCommand = new DelegateCommand<LightSourceFilterItem>(RemoveLightSource);MoveUpCommand = new DelegateCommand<LightSourceFilterItem>(MoveUp);MoveDownCommand = new DelegateCommand<LightSourceFilterItem>(MoveDown);}private void AddLightSource(){if (string.IsNullOrWhiteSpace(NewLightSourceName)) return;if (LightSourceItems.Any(x => x.Name == NewLightSourceName)) return;LightSourceItems.Add(new LightSourceFilterItem(NewLightSourceName));NewLightSourceName = string.Empty;}private void RemoveLightSource(LightSourceFilterItem item){if (item != null)LightSourceItems.Remove(item);}private void MoveUp(LightSourceFilterItem item){var index = LightSourceItems.IndexOf(item);if (index > 0)LightSourceItems.Move(index, index - 1);}private void MoveDown(LightSourceFilterItem item){var index = LightSourceItems.IndexOf(item);if (index < LightSourceItems.Count - 1)LightSourceItems.Move(index, index + 1);}
}

💡 温馨提示
使用 ObservableCollection.Move() 可以高效地重排项,UI 会自动更新。

如果你未来打算支持拖动排序,也可以换成 ListBox + drag-and-drop 实现。


🎨 第三步:编写 XAML 界面

<UserControl x:Class="MainPro.Views.LightTypeView"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:prism="http://prismlibrary.com/"prism:ViewModelLocator.AutoWireViewModel="True"Background="AliceBlue"><StackPanel Margin="20"><!-- 添加区域 --><StackPanel Orientation="Horizontal" Margin="0,0,0,10"><TextBox Width="150"Text="{Binding NewLightSourceName, UpdateSourceTrigger=PropertyChanged}" /><Button Content="添加光源类型" Command="{Binding AddLightSourceCommand}" Margin="10,0,0,0" /></StackPanel><!-- 光源列表 --><ItemsControl ItemsSource="{Binding LightSourceItems}"><ItemsControl.ItemTemplate><DataTemplate><StackPanel Orientation="Horizontal" Margin="5"><CheckBox Content="{Binding Name}"IsChecked="{Binding IsChecked, Mode=TwoWay}" /><Button Content="" Margin="10,0,0,0"Command="{Binding DataContext.MoveUpCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"CommandParameter="{Binding}" /><Button Content="👇" Margin="5,0,0,0"Command="{Binding DataContext.MoveDownCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"CommandParameter="{Binding}" /><Button Content="" Foreground="Red" Margin="5,0,0,0"Command="{Binding DataContext.RemoveLightSourceCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"CommandParameter="{Binding}" /></StackPanel></DataTemplate></ItemsControl.ItemTemplate></ItemsControl></StackPanel>
</UserControl>

🔍 第四步:效果展示

✅ 添加新项后立即出现在下方
❌ 删除指定项
🔼🔽 可调整顺序,数据集合自动更新 UI
在这里插入图片描述


📝 总结

这个小型项目展示了:

  • 如何结合 ObservableCollectionItemsControl 构建交互式列表
  • 如何用 Prism 的 DelegateCommand<T> 实现项级操作
  • 使用 MVVM 保持代码整洁、解耦、易维护

这种思路不仅适用于光源类型管理,也适合于任何需要用户自定义数据项列表的场景。


📎 如需源码或进一步扩展功能(如拖拽排序、持久化到配置文件等),欢迎留言!如果这篇文章对你有帮助,欢迎收藏+转发 ❤️


文章转载自:

http://5iRH1Se4.gxkLx.cn
http://sV1JQ5XP.gxkLx.cn
http://9dZFpwiU.gxkLx.cn
http://W4lVJwd9.gxkLx.cn
http://r0G8amm6.gxkLx.cn
http://iTG8JjMM.gxkLx.cn
http://qy3RTVXt.gxkLx.cn
http://46Z16CbI.gxkLx.cn
http://W03r2ziM.gxkLx.cn
http://7ftBKRLn.gxkLx.cn
http://qXQ7BvgF.gxkLx.cn
http://f4CMP6AE.gxkLx.cn
http://VWxmTbDL.gxkLx.cn
http://nk4cVyEu.gxkLx.cn
http://YXN9JguD.gxkLx.cn
http://75dkOXMh.gxkLx.cn
http://tYj8YRPH.gxkLx.cn
http://dPxf6TAA.gxkLx.cn
http://Hp14etnq.gxkLx.cn
http://m4p3dOla.gxkLx.cn
http://6DX4kgzt.gxkLx.cn
http://s1eW6AE2.gxkLx.cn
http://gfbsUCPG.gxkLx.cn
http://TT9todR5.gxkLx.cn
http://CREELhJp.gxkLx.cn
http://lvmm5V2C.gxkLx.cn
http://IkTI6vjv.gxkLx.cn
http://DxhNRKvq.gxkLx.cn
http://QG2IYTG0.gxkLx.cn
http://TcwYi338.gxkLx.cn
http://www.dtcms.com/wzjs/637089.html

相关文章:

  • 影视 网站建设 新媒体wordpress代码高亮主题
  • 中山市网站建设哪家好租房合同 模板
  • 品牌网站建设e小蝌蚪制作网站付款方式
  • 海阳网站建设深圳网站建设补助
  • 深圳医疗网站建设公司中山网站建设文化教程
  • 设计一个网站的步骤wordpress点击网页效果
  • 模板网站制作公司网站建设匠人匠心科技
  • 如何给网站添加外链白酒pc网站建设方案
  • 个人网站wordpress高端网站制作平台
  • 教育公司网站建设方案推荐几个自学做衣服的网站
  • 怎么做一元购网站地税网站建设管理
  • 学院网站建设推进会宣讲家网站 家风建设
  • 北京网站网页设计企业门户网站建设渠道
  • 商丘家具网站建设辽宁住房和城乡建设部网站
  • 网站推广一般办法外贸免费开发网站建设
  • 北京做手机网站做网站要写代码吗
  • wordpress 什么值得买 我要爆料泰安企业网站seo
  • 网站建设 竞赛 方案千锋教育视频
  • 传媒公司logo设计创意网站文件名优化
  • 南沙开发区建设和交通局网站做企业网站的费用挂什么科目
  • 软件编程和网站开发差别wordpress电脑图片尺寸
  • 51比购网官方网站河北网站建设推广公司
  • 盐城做网站需要多少钱网上购物网站开发背景
  • 网站控制面板美丽定制 网站模板
  • 新建茶叶网站文章内容建设网站建设公司推荐互赢网络
  • 网站按钮样式网站如何添加二维码
  • 金华建设工程网站陕西省住建厅官网
  • 网站一次性建设建设网站公司怎么分工
  • 共享互助医疗网站建设机械外贸网站建设
  • 应该符合建设网站对手网站分析