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

problem with command bound to SeletcedItem

1 Answer 128 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Valentin
Top achievements
Rank 1
Valentin asked on 23 May 2014, 12:43 PM
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.

1 Answer, 1 is accepted

Sort by
0
Polya
Telerik team
answered on 27 May 2014, 10:10 AM
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.
 
Tags
ListBox
Asked by
Valentin
Top achievements
Rank 1
Answers by
Polya
Telerik team
Share this question
or