0
votes

If i load string value in dependency property "Text" of ComboBox. ComboBox does not pair string value with ItemsSource objects and i don't have SelectedItem filled.

Need SelectedItem for ToolTip!!

<ComboBox x:Name="FieldComboBox" IsEditable="True" IsTextSearchEnabled="True"                          
          Text="{Binding Text, UpdateSourceTrigger=PropertyChanged}"
          DisplayMemberPath="DataCode" 
          ItemsSource="{Binding FieldAlternative.FieldParts[0].DataItems}"
          ToolTip="{Binding Path=SelectedItem.Description, ElementName=FieldComboBox}"/>     

If i've empty Text and write, it works fine. If i've opened form with value in Text i have SelectedItem null but value Text is displayed.

Any solution how to forced pairing Text with objects in ItemsSource to fill SelectedValue, or any better solution of my problem.

Thx

1

1 Answers

0
votes

You can set a default value to your combobox by the SelectedItem property which will be binded to your Text Field in your ViewModel:

SelectedItem="{Binding Path=Text, Mode=TwoWay}"

So your combobox element becomes like this:

<ComboBox x:Name="FieldComboBox" IsEditable="True" IsTextSearchEnabled="True"                          
          Text="{Binding Text, UpdateSourceTrigger=PropertyChanged}"
          SelectedItem="{Binding Path=Text, Mode=TwoWay}"
          DisplayMemberPath="DataCode" 
          ItemsSource="{Binding FieldAlternative.FieldParts[0].DataItems}"
          ToolTip="{Binding Path=SelectedItem.Description, ElementName=FieldComboBox}"/>