The ListBox control does not implement a Command property. I have to attach some functionality to the SelectionChanged event. Somebody knows how can I do it? Please help me
相关问题
- how to Enumerate local fonts in silverlight 4
- Free Silverlight mapping with Bing maps and OpenSt
- Custom number picker?
- ObservableCollection in ViewModel is not updated w
- Error using ResourceDictionary in Silverlight
相关文章
- XAML ComboBox SelectionChanged Fires OnLoad
- Best way to implement MVVM bindings (View <-> V
- New Windows Application - What language?
- relative url in wcf service binding
- Using LiveData to set visibility of TextView
- app:visibleGone cannot resolve on android Databind
- Embedded images not showing when in a UserControl
- PowerShell Pass Named parameters to ArgumentList
This is the way where You can Reach the Selection changed events in Your MVVM Application First Of all i tell you that Command Property only work in Button now we have to Explicitly binding that property in our Selection Changed event like List box or combo box in Your XMAL file
for this you have to add dll Syatem.Windows.Interactivity now u have to add references in your xaml file namespace like
in your ViewModel Class you have to define your Command in Con structure
now create the TestMethod method which can handle the selection changed event
i hope this may help u.
I prefer using a binding to the
SelectedItem
and implementing any functionality in the setting of the binding property....
I would suggest using
RelayCommand
. Either use the MVVM Light Toolkit or just use theRelayCommand
andCommandManager
classes from Josh Smith's implementations. I personally use just the two classes, so I don't need the entire toolkit.While this will definitely work, there might be an easier way depending on what you are doing. It might just be easier to bind an object to the
SelectedValue
of theListBox
and listen for that value to change.Think this post from Laurent Bugnion will help you solve the problem:
http://geekswithblogs.net/lbugnion/archive/2010/05/19/handling-datagrid.selecteditems-in-an-mvvm-friendly-manner.aspx
The post above mentions the DataGrid but I do think it will work with the ListBox too!
Best regards and Happy New Year!! :)
Basically you have a few options:
SelectionChanged
event and execute a command (the command could be a dependency property exposed by the behavior).