Page 1 of 1
Displaying selected item in databound Combobox
Posted: 07 Feb 2014, 11:27
by Andreas Schooll
Hey,
i have a combobox that is databound to a collection with multiple informations. The xaml looks like this:
<ComboBox x:Name="combobox" SelectedValue="{Binding LanguageText}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding LanguageText}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
The combobox will be populated and the selection is also working as expected.
The problem is, that the selected value won't show up in the ToggleButton area. The ToggleButton area stays empty all the time.
I tried setting the properties like SelectedValue and SelectedValuePath to everything i could imagine but without any success.
What am i doing wrong or what am i missing?
best regards,
Andreas
PS: If i don't use ItemTemplate and just use combobox.GetItems().Add(item) with plain strings to populate the combobox then the selection will show up properly.
Re: Displaying selected item in databound Combobox
Posted: 07 Feb 2014, 17:44
by sfernandez
The properties Selector.SelectedValue and Selector.SelectedValuePath are not implemented. Changing selected value does not update the selected item, and changing the selected item does not update the selected value.
We will add it to our feature list and implement it as soon as possible. Meanwhile you have to select the desired item via SelectedItem or SelectedIndex properties.
Sorry for the inconvenience

Re: Displaying selected item in databound Combobox
Posted: 10 Feb 2014, 12:22
by Andreas Schooll
Hey thanks for your response,
my problem is not selecting the desired item as i already select it via the index.
My Problem is that the selection does not show up in the toggle button after selecting the item. The toggle button stays emtpy all the time. Is there anything i can do about this?
best regards,
Andreas
Re: Displaying selected item in databound Combobox
Posted: 10 Feb 2014, 14:01
by sfernandez
I understand the problem now.
You will need to specify the SelectionBoxItemTemplate to define how to show the selected item in the combo box:
<ComboBox Width="200" VerticalAlignment="Center" ItemsSource="{Binding}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
<ComboBox.SelectionBoxItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ComboBox.SelectionBoxItemTemplate>
</ComboBox>
Re: Displaying selected item in databound Combobox
Posted: 10 Feb 2014, 16:41
by Andreas Schooll
This is exactly what i needed. Thanks a lot.
Re: Displaying selected item in databound Combobox
Posted: 19 Jun 2014, 03:38
by kayrk
I understand the problem now.
You will need to specify the SelectionBoxItemTemplate to define how to show the selected item in the combo box:
<ComboBox Width="200" VerticalAlignment="Center" ItemsSource="{Binding}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
<ComboBox.SelectionBoxItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ComboBox.SelectionBoxItemTemplate>
</ComboBox>
This also worked for me the only problem I have is blend is complaining about ComboBox.SelectionBoxItemTemplate - The property "SelectionBoxItemTemplate" does not have an accessible setter. How do I fix that?
Re: Displaying selected item in databound Combobox
Posted: 21 Jun 2014, 00:17
by sfernandez
This also worked for me the only problem I have is blend is complaining about ComboBox.SelectionBoxItemTemplate - The property "SelectionBoxItemTemplate" does not have an accessible setter. How do I fix that?
It seems that we have a deviation here from WPF. I've been investigating this issue and it turns out that SelectionBoxItemTemplate is read-only because it is a calculated value. It should be internally set to the corresponding DataTemplate specified by ItemTemplate/ItemTemplateSelector depending on the selected item.
We will try to fix it for the following release.
Meanwhile the only (ugly) solution is to comment the SelectionBoxItemTemplate while working in Blend, and uncomment when you want to see the results in Unity

Re: Displaying selected item in databound Combobox
Posted: 21 Jun 2014, 00:18
by kayrk
Yeah that's what I've been doing thanks.
Re: Displaying selected item in databound Combobox
Posted: 27 Jun 2014, 15:18
by sfernandez
Yeah that's what I've been doing thanks.
In the following release (1.1.9), we will make ComboBox.SelectionBoxItemTemplate property Read-Only to match WPF API, and the template will automatically be assigned, corresponding to the template used to represent the selected item in the list.