Reputation: 43
I have the same ItemsControl I use to display multiple Combo boxes. Ex. The same template is used to display, sometime combo box with some names, and sometime combo box with some firstnames, according to the items list which is bound to the ItemsControl.
In the template, the ComboBox's SelectedValue is bound to only one property called "ReceivedCBValue". So, sometimes, the selected value gives me firstnames, sometimes names. but how can I know if I got a name or a first name?
In another way, i have the same kind of problem with text Boxes : the same template is used to display sometime text box which will receive names, sometime text box which will receive firstnames. Once again, the text box, in the template, is bound to only one property, "receivedTextValue".
I display several of my text boxes at the same time, and when I type some text in one of them, the other text boxes display the text I just typed. Finally, I have multiple text Box with the same value. Absolutely useless.
<ItemsControl Background="BurlyWood" Margin="20" Name="IcChoice"
ItemsSource="{Binding Items, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Width="350"
Height="200"
Tag="{Binding Tag, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Margin="5" Background="Brown"
Visibility="{Binding Visible, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- ComboBox Source is bound to the Children List, whereas its selectedValue is bound to ReceivedCBValue on the main DataContext ( Hello), so to the ViewModel -->
<ComboBox Grid.Column="0"
ItemsSource="{Binding Children}"
Visibility="{Binding ComboBoxVisibility}"
SelectedValue="{Binding DataContext.ReceivedCBValue, ElementName=Hello, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
Grid.Row="1" />
<ComboBox Grid.Column="0"
ItemsSource=""></ComboBox>
<TextBox
Text="{Binding DataContext.ReceivedText,
ElementName=Hello,
UpdateSourceTrigger=PropertyChanged,
Mode=TwoWay}"
Grid.Row="1" />
Upvotes: -2
Views: 65
Reputation: 43
I think I understood where i'm wrong, and why.
I use those ItemsControls and their content to apply filter on a List (Or an ObservableCollection), and before I understood, i wanted to apply filter "directly" with the value typed (that's why i wanted to get the value in my view model (typedValue
-> ViewModel.ReceivedValue
-> applyFilter(ViewModel.ReceivedValue);
).
Now, I know that i have to set all the values in a DisplayedIteml object's properties, send this object to my viewModel (or something like that), and apply my filter with that object's values.
Upvotes: 0