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

}

相关推荐
a程序小傲18 小时前
得物Java面试被问:方法句柄(MethodHandle)与反射的性能对比和底层区别
java·开发语言·spring boot·后端·python·面试·职场和发展
IT_陈寒18 小时前
Java并发编程实战:从入门到精通的5个关键技巧,让我薪资涨了40%
前端·人工智能·后端
全栈前端老曹18 小时前
【包管理】read-pkg-up 快速上手教程 - 读取最近的 package.json 文件
前端·javascript·npm·node.js·json·nrm·package.json
酒书18 小时前
对接阿里云号码认证实现运营商一键登录
java·阿里云
独自破碎E18 小时前
比较版本号
java·开发语言
zimoyin18 小时前
浅浅了解下0拷贝技术
java·linux·开发语言
故事不长丨18 小时前
Java List集合深度解析:从基础用法到实战技巧
java·链表·list·集合
程序员爱钓鱼18 小时前
Node.js 编程实战:测试与调试 —— 调试技巧与性能分析
前端·后端·node.js
JQLvopkk18 小时前
Vue框架技术详细介绍及阐述
前端·javascript·vue.js
vyuvyucd18 小时前
插件式开发:C++与C#实战指南
java·前端·数据库