This is a migrated thread and some comments may be shown as answers.

Update Text during initialization when binding MultiSelect

1 Answer 125 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Magnus
Top achievements
Rank 1
Magnus asked on 27 Sep 2017, 02:16 PM

I've got a combobox with MultiSelection, and in order to implement proper binding of selected items I use the following style:

 

    <telerik:RadComboBox.ItemContainerStyle>
          <Style TargetType="telerik:RadComboBoxItem">
                <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}}" />
          </Style>
    </telerik:RadComboBox.ItemContainerStyle>

 

The binding of the selection works both ways, but unfortunately the Text-property isn't initialized to my set of selected items. The combobox remains empty until i open its dropdown, and then the Text-property is set. Seems like a bug, but is there maybe a way to get around it?

1 Answer, 1 is accepted

Sort by
0
Accepted
Kalin
Telerik team
answered on 02 Oct 2017, 12:34 PM
Hello Magnus,

This is expected behavior as binding gets triggered one the ComboBoxItem containers are initialized. And they get initialized the first time the drop down is opened. In other words there isn't selection until the drop down is opened. The quickest solution would be to manually open and close the drop when the control is loaded:
private void RadComboBox_Loaded(object sender, RoutedEventArgs e)
{
    (sender as RadComboBox).IsDropDownOpen = true;
    (sender as RadComboBox).IsDropDownOpen = false;
}

Or you could check the following example from our online Xaml SDK repository demonstrating how to implement custom SelectedItemsBehavior:
https://github.com/telerik/xaml-sdk/tree/master/ComboBox/SelectedItemsBinding

Hope this helps.

Regards,
Kalin
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
ComboBox
Asked by
Magnus
Top achievements
Rank 1
Answers by
Kalin
Telerik team
Share this question
or