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

}

相关推荐
超级小忍5 分钟前
JVM 中的垃圾回收算法及垃圾回收器详解
java·jvm
weixin_446122468 分钟前
JAVA内存区域划分
java·开发语言·redis
小小小小宇8 分钟前
虚拟列表兼容老DOM操作
前端
悦悦子a啊10 分钟前
Python之--基本知识
开发语言·前端·python
勤奋的小王同学~35 分钟前
(javaEE初阶)计算机是如何组成的:CPU基本工作流程 CPU介绍 CPU执行指令的流程 寄存器 程序 进程 进程控制块 线程 线程的执行
java·java-ee
TT哇36 分钟前
JavaEE==网站开发
java·redis·java-ee
2401_8260976240 分钟前
JavaEE-Linux环境部署
java·linux·java-ee
安全系统学习1 小时前
系统安全之大模型案例分析
前端·安全·web安全·网络安全·xss
缘来是庄1 小时前
设计模式之访问者模式
java·设计模式·访问者模式
涛哥码咖1 小时前
chrome安装AXURE插件后无效
前端·chrome·axure