c# - 组合框的 WPF 不同 ItemsSource

标签 c# wpf xaml combobox

我想将 bool 值、对象列表和枚举值绑定(bind)到组合框。根据数据网格的列弹出一个对话框,我加载一个对象列表(Object1.Name....ObjectN.Name 是名称,ObjectId1..ObjectIdN 是 Id),我加载一个 EnumValue 列表(EnumItem1..EnumItemN是名称,EnumValue1 .. EnumValueN 是 Id)或 bool 值(是/否是名称,0/1 是 Id)。

我该怎么做?我是否需要在我的 ViewModel 中为我的组合框实现包装类? (这个包装类将获取对象列表, bool 值列表是/否,枚举值列表)。

最佳答案

 <Style Target={x:Type ComboBox}>
   <Style.Triggers>
       <DataTrigger Binding="{Path=RowData.Row.PropertyToBeChecked}" Value="Value1">
           <Setter Property="DataSource" Value="{Binding Path=ListCorrespondingToValue1}"/>
       </DataTrigger>
       <DataTrigger Binding="{Path=RowData.Row.PropertyToBeChecked}" Value="Value2">
           <Setter Property="DataSource" Value="{Binding Path=ListCorrespondingToValue2}"/>
       </DataTrigger>
   </Style.Triggers>
</Style>

关于c# - 组合框的 WPF 不同 ItemsSource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20263986/

相关文章:

c# - 如何在移动设备或平板电脑时重定向到移动页面?

c# - 如何获取所有引用程序集的列表(已加载或未加载)

c# - Dictionary<TKey, TValue> 中的键是不可变的吗?

c# - Datagrid 行样式绑定(bind)到动态更改的属性

c# - 当绑定(bind)的 ObservableCollection 更改时 ListView 不更新

c# - wpf mvvm 中的 Datagrid SelectedIndex 在 RaisePropertyChanged 上设置为 0

c# - 跟踪套接字(文件)描述符回到绑定(bind)地址

WPF MessageBox 默认取消

wpf - ListView.ItemTemplate中的SharedSizeGroup

C#/WPF : Can I Store more that 1 type in Clipboard?