-2

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" />
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Ch4BRN
  • 43
  • 4
  • People pull me points, but I don't understand why ...? Give me some leads, at least, please. I did some research, but could not find a suitable answer. I am a beginner in WPF, there are some concepts, some principles that I don't understand very well, or that I just don't know. Not to mention that I don't speak a very very good English, which complicates the research (it's interesting, but time consuming). – Ch4BRN Apr 18 '18 at 11:13
  • Your question is very confusing... Are you talking about the data you are loading from the database? You can't tell where you are loading the data from? Firstname or Name? Maybe post the viewmodel class so we can figure out what you mean? – Kevin Cook Apr 18 '18 at 13:56
  • Thanks for your answer. – Ch4BRN Apr 18 '18 at 14:36
  • In fact, I have an ObservableCollection, in my ViewModel, bound to a comboBox in my View. In this observable Collection, i have some DisplayedItems, some object that are actually ( if I well understood) the "base" object to create my ItemsControl. Each of thes objects contains a string property and a List. In the template of my items control, the list is bound to a combobox and the string is bound to a TextBox. As I have several Items Controls (One with a textField destined to receive name, one with a textField destined to receive FirstName, but built from the same template .... – Ch4BRN Apr 18 '18 at 14:44
  • ... The first observable collection allows me to chose which one of the items control i want to display, and that works, but then, when i have, the Name items control and the firstname items control displayed on my view, i can't differentiate the data origins ( name text box/itemsCOntrol or firstname textbox/itemsControl?) is it clearer? – Ch4BRN Apr 18 '18 at 14:47
  • Its names and first names typed by user ! – Ch4BRN Apr 18 '18 at 14:49

1 Answers1

0

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.

Ch4BRN
  • 43
  • 4