Andreas Schooll
Topic Author
Posts: 25
Joined: 30 Sep 2013, 16:58

Displaying selected item in databound Combobox

07 Feb 2014, 11:27

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.
 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: Displaying selected item in databound Combobox

07 Feb 2014, 17:44

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 :(
 
Andreas Schooll
Topic Author
Posts: 25
Joined: 30 Sep 2013, 16:58

Re: Displaying selected item in databound Combobox

10 Feb 2014, 12:22

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
 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: Displaying selected item in databound Combobox

10 Feb 2014, 14:01

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>
 
Andreas Schooll
Topic Author
Posts: 25
Joined: 30 Sep 2013, 16:58

Re: Displaying selected item in databound Combobox

10 Feb 2014, 16:41

This is exactly what i needed. Thanks a lot.
 
kayrk
Posts: 41
Joined: 07 May 2014, 19:41

Re: Displaying selected item in databound Combobox

19 Jun 2014, 03:38

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?
 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: Displaying selected item in databound Combobox

21 Jun 2014, 00:17

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 :?
 
kayrk
Posts: 41
Joined: 07 May 2014, 19:41

Re: Displaying selected item in databound Combobox

21 Jun 2014, 00:18

Yeah that's what I've been doing thanks.
 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: Displaying selected item in databound Combobox

27 Jun 2014, 15:18

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.

Who is online

Users browsing this forum: Ahrefs [Bot] and 55 guests