Update Text during initialization when binding MultiSelect

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

    Posted 27 Sep 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:

     

        <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?

  2. Kalin
    Admin
    Kalin avatar
    1279 posts

    Posted 02 Oct 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:
    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.
Back to Top