2

I want to bind a boolean values, list of objects and enum values to a combobox. Depending on the column of a datagrid pops a dialog and I load a list of objects (Object1.Name....ObjectN.Name are Names and ObjectId1..ObjectIdN are Id's), I load a list of EnumValue (EnumItem1..EnumItemN are Names, EnumValue1 .. EnumValueN are Id's), or boolean (Yes/No are Names, and 0/1 the Id's).

How can I do it? Do I need to implement a wrap class in my ViewModel for my combobox? (this wrap class would get list of objects, list yes/no for booleans, list of enumvalues).

MrScf
  • 2,407
  • 5
  • 27
  • 40

2 Answers2

2
 <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>
Franck Ngako
  • 163
  • 6
1

well, for me i think you can achieve your goal with a trigger in which you set the dataSource of your combo box. it will look like

<Style Target={x:Type ComboBox}>

Franck Ngako
  • 163
  • 6
  • Cool, thanks. But it means, I should have one property in ViewModel for kind of list. Is it not better to have one property that provides always the correct values? – MrScf Nov 28 '13 at 11:23
  • well is not that easy because you can bind your datasource to one and only one property. i'm not able to tell you how you will do with an object wrapping your two type of list. – Franck Ngako Nov 28 '13 at 11:43
  • And yes you'll have to defind two distinct property in your viewModel List and List or you simply can add yes or no in your enumeration and depending on your datagrid column refresh you dataSource with linq like list = list.Where(l => l.val != enum.yes && l.val!= enum.No) – Franck Ngako Nov 28 '13 at 11:46
  • Ok, cool you are right. I find too difficult bind my combobox to one and only one property. I will take this way. Thanks! – MrScf Nov 28 '13 at 11:47