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

}

相关推荐
Asmewill13 分钟前
grep&curl命令学习笔记
前端
stringwu16 分钟前
Flutter 开发必备:MVI 架构的高效实现指南
前端·flutter
用户2136610035721 小时前
Vue2组件化开发与父子通信
前端·vue.js
祎雪双十Gy2 小时前
从 DataX 的配置加载说起:我用 FastJson2 做了一个轻量级动态配置管理库
java·后端
Momo__2 小时前
TypeScript satisfies 操作符——比 as 更安全的类型守门员
前端·typescript
用户2136610035722 小时前
Vue2事件系统与指令进阶
前端·vue.js
labixiong2 小时前
实现一个能跑的迷你版Promise(一)
前端·javascript·面试
小锋java12342 小时前
分享一套锋哥原创的SpringBoot4+Vue3宠物领养网站系统
java
Csvn4 小时前
`??` 和 `||` 搞混,线上用户头像全挂了
前端
kyriewen4 小时前
白宫前脚下了限制令,OpenAI 后脚就把 GPT-5.6 发了
前端·gpt·openai