problem with command bound to SeletcedItem

2 posts, 0 answers
  1. Valentin
    Valentin avatar
    1 posts
    Member since:
    May 2014

    Posted 23 May 2014 Link to this post

    I have a ListBox bound to collection of items, which each defines its Command in the ViewModel.
    The SelectedItem is Bound to the ViewModel of the ListBox itself with TwoWay-Binding since I need to change Selection from Code.
    Short version looks like this.

    <
    telerik:RadListBox ItemsSource="{Binding Items}" 
    ItemTemplate
    ="{StaticResource ItemTemplate}" 
    SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
                        Command="{Binding SelectedItem.Command}"
     SelectionMode="Single"
    >
    Now I've encountered the problem, that if I set SelectedItem in the ViewModel to 'null', the Item thats just been DeSelected still fires its Command one more time, which I personally would consider a bug.

    Also this leads to an interesting behaviour in my app...

    Someone any ideas, other than to create an event Handler for Selection changed and fire the Command from CodeBehind?

    Any suggestions would be much appreciated.
    Thx a bunch.
  2. Polya
    Admin
    Polya avatar
    200 posts

    Posted 27 May 2014 Link to this post

    Hello Valentin,

    When setting the SelectedItem to null in the code behind the command is fired because internally in RadListBox we execute the command when the selection changes. As the ViewModel SelectedItem is bound to the RadListBox SelectedItem, setting the first to null causes a change in the selection.

    Can you please provide more information, code samples or example to give more inside on the interesting behavior that occurs in your solution in order for me to assist you further.

    Looking forward to your reply.

    Regards,
    Polya
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top