gpt4 book ai didi

c# - 使用标记方法将 Item Sourcing 转换为 ComboBox

转载 作者:太空宇宙 更新时间:2023-11-03 13:07:10 25 4
gpt4 key购买 nike

我有一个 ComboBox

<ComboBox x:Name="SearchGendersComboBox" Grid.Row="3" Grid.Column="1"
IsEditable="True"
SelectedValuePath="Key"
DisplayMemberPath="Value"
SelectedValue="{Binding Path=GenderId}"

/>

我用这个来填充它:

public void BindComboBoxes()
{
SearchGendersComboBox.ItemsSource = new BindingSource(GenderMgr.GetGendersDropDown(true), null);
SearchGendersComboBox.SelectedIndex = 0;
}

这是GenderMgr:

public class GenderMgr
{

public static Dictionary<byte, string> GetGendersDropDown(bool isFilterMode = false)
{
return GenderDb.RetrieveGendersDropDown(isFilterMode);
}

}

如何使用标记中的 GenderMgr.GetGendersDropDown 填充 ComboBox

最佳答案

去掉BindingSourceItemsSource应该直接是GenderMgr.GetGendersDropDown(true),即字典。其他一切看起来都很好。

至于转换为标记:在某些时候您需要从某个地方获取对象,因此除了使用 ObjectDataProvider 调用 XAML 中的相应数据提供方法之外,您无能为力。通常你会有一些属性来保存 View 模型中的项目,然后 ItemsSource 仍然可以绑定(bind)在 XAML 中;只要 View 模型支持更改通知,就可以在数据可用的任何时候分配属性。

关于c# - 使用标记方法将 Item Sourcing 转换为 ComboBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30379938/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com