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);

}

相关推荐
肥肠可耐的西西公主6 分钟前
前端(AJAX)学习笔记(CLASS 2):图书管理案例以及图片上传
前端·笔记·学习
大胖丫8 分钟前
vue 学习-vite api.js
开发语言·前端·javascript
孙桂月9 分钟前
ES6相关操作(2)
前端·javascript·es6
陈浩源同学9 分钟前
学习 TypeScript 栈和队列数据结构
前端·算法
我这一生如履薄冰~11 分钟前
简单封装一个websocket构造函数
前端·javascript·websocket
fangcaojushi11 分钟前
解决webpack5.54打包图片及图标的问题
前端·vue.js
海盗强12 分钟前
Webpack打包优化
前端·webpack·node.js
星之卡比*14 分钟前
前端面试题---vite和webpack的区别
前端·面试
^^为欢几何^^19 分钟前
npm、pnpm和yarn有什么区别
前端·npm·node.js
布谷歌21 分钟前
Oops! 更改field的数据类型,影响到rabbitmq消费了...(有关于Java序列化)
java·开发语言·分布式·rabbitmq·java-rabbitmq