Update Text during initialization when binding MultiSelect

2 posts, 1 answers
  1. Magnus
    Magnus avatar
    24 posts
    Member since:
    Dec 2011

    Posted 27 Sep 2017 Link to this post

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


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


    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?

  2. Answer
    Kalin avatar
    1312 posts

    Posted 02 Oct 2017 Link to this post

    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:

    Hope this helps.

    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.
Back to Top