WPF的下拉复选框多选,数据来源数据库的表

页面控件使用

<Label Style="{StaticResource ListSearch-Label}" Content="走货方式:"/>

<c1:C1ComboBox BorderThickness="1" Width="110"

<xctk:CheckComboBox Width="113" Style="{StaticResource ListSearch-XctkCheckComboBox}"

ItemsSource="{Binding ShippmentWayList,Mode=TwoWay}"

DisplayMemberPath="ShipWay" ValueMemberPath="ShipWay"

SelectedItemsOverride="{Binding ShippmentWayItems,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,

ValidatesOnExceptions=True, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"

SelectedValue="{Binding ShippmentWay, Mode=TwoWay}"/>

cs

private ObservableCollection<dynamic> _shippmentWayItems;

private string _shippmentWay;

public string ShippmentWay

{

get

{

return _shippmentWay;

}

set

{

if (_shippmentWay != null && _shippmentWay.Contains("-1") && value != null && !value.Contains("-1"))

{

_shippmentWayItems = new ObservableCollection<dynamic>() { };

}

//等于-1这个可以护理,我的key和value用的都是中文

else if (_shippmentWay != null && !_shippmentWay.Contains("-1") && value != null && value.Contains("-1"))

{

_shippmentWay = InitWayStatus();

_shippmentWayItems = new ObservableCollection<dynamic>() { };

foreach (var item in ShippmentWayList)

{

_shippmentWayItems.Add(new { name = item.ShipWay, value = item.ShipWay });

}

}

_shippmentWay = value;

if (SearchItem != null)

{

SearchItem.ShippmentWay = _shippmentWay;

}

RaisePropertyChanged(() => ShippmentWayItems);

RaisePropertyChanged(() => ShippmentWay);

}

}

/// <summary>

/// 获取所有走货方式数据来源数据库

/// </summary>

private void GetShipingWayList()

{

string error;

var list = _shipWayService.FindByIsShip((int)_fSaleType, out error);

if (list == null)

{

ShippmentWayList = new ObservableCollection<ShipWayModel>();

}

else

{

ShippmentWayList = new ObservableCollection<ShipWayModel>(list);

}

RaisePropertyChanged(() => ShippmentWayList);

}

/// <summary>

/// 默认走货方式的状态初始化,把这个方法放在初始化种

/// </summary>

/// <returns></returns>

private string InitWayStatus()

{

var list = new List<string>();

if (ShippmentWayList==null) {

GetShipingWayList();

}

foreach (var item in ShippmentWayList)

{

list.Add(item.ShipWay);

}

return string.Join(",", list);

}

相关推荐
清空mega14 分钟前
《Vue Router 与 Pinia 入门:页面跳转、动态路由、全局状态管理一篇打通》
前端·javascript·vue.js
踩着两条虫14 分钟前
AI 驱动的 Vue3 应用开发平台 深入探究(十):物料系统之内置组件库
前端·vue.js
深蓝轨迹20 分钟前
IDEA 中 Spring Boot 配置文件的自动提示消失(无法扫描配置文件)的完整解决方案
java·spring boot·intellij-idea
杀神lwz23 分钟前
Java Json压缩工具类
java·json
虾..24 分钟前
Linux 基于TCP实现服务端客户端通信(线程池)
java·网络协议·tcp/ip
前端小雪的博客.28 分钟前
【Java 基础】变量全解:定义、命名规范、作用域与常量(附代码示例+面试题)
java·作用域·java基础·java入门·变量·常量·java面试题
mldlds37 分钟前
【异常解决】Unable to start embedded Tomcat Nacos 启动报错
java·tomcat
代码探秘者39 分钟前
【Java】final、finally、finalize 区别
java·开发语言
代码探秘者44 分钟前
【Java】浅拷贝 VS 深拷贝:核心差异 + 实现方式 + 避坑指南
java·开发语言
坚持学习前端日记1 小时前
AI 产品开发经验
前端·javascript·人工智能·visual studio