-
- Andreas Schooll
- Posts: 25
- Joined:
Displaying selected item in databound Combobox
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.
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.
-
-
sfernandez
Site Admin
- Posts: 2908
- Joined:
Re: Displaying selected item in databound Combobox
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
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

-
- Andreas Schooll
- Posts: 25
- Joined:
Re: Displaying selected item in databound Combobox
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
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
-
-
sfernandez
Site Admin
- Posts: 2908
- Joined:
Re: Displaying selected item in databound Combobox
I understand the problem now.
You will need to specify the SelectionBoxItemTemplate to define how to show the selected item in the combo box:
You will need to specify the SelectionBoxItemTemplate to define how to show the selected item in the combo box:
Code: Select all
<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>
-
- Andreas Schooll
- Posts: 25
- Joined:
Re: Displaying selected item in databound Combobox
This is exactly what i needed. Thanks a lot.
Re: Displaying selected item in databound 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?I understand the problem now.
You will need to specify the SelectionBoxItemTemplate to define how to show the selected item in the combo box:
Code: Select all<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>
-
-
sfernandez
Site Admin
- Posts: 2908
- Joined:
Re: Displaying selected item in databound Combobox
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.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?
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
Yeah that's what I've been doing thanks.
-
-
sfernandez
Site Admin
- Posts: 2908
- Joined:
Re: Displaying selected item in databound Combobox
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.Yeah that's what I've been doing thanks.
Who is online
Users browsing this forum: Ahrefs [Bot] and 3 guests