data binding - Adding MouseBindings to Items in a databound WPF ListView -


I am trying to get a command executed on my ViewModel when a user clicks on an item in a ListView. When I add a ListViewItem to XAM, I can add mousebending to my InputBindings .

  & lt; ListView & gt; & Lt; ListView.View & gt; & Lt; GridView & gt; & Lt; GridViewColumn header = "test" /> & Lt; / GridView & gt; & Lt; /ListView.View> & Lt; ListViewItem content = "item 1" & gt; & Lt; ListViewItem.InputBindings & gt; & Lt; Mousebinding gesture = "left wclick" command = "{binding doubleclick command}" /> & Lt; /ListViewItem.InputBindings> & Lt; / ListViewItem & gt; & Lt; / ListView & gt;  

But how can it be achieved in a databaund list view?

  & lt; ListView ItemsSource = "{Binding Patients}" & gt; & Lt; ListView.View & gt; & Lt; GridView & gt; & Lt; GridViewColumn header = "test" / & gt; & Lt; / GridView & gt; & Lt ;! - How to set mousebending for generated ListViewItems ?? - & gt; & Lt; /ListView.View>   

I found a solution by defining the ListViewItem style and by changing ControlTempalte to ListViewItem . However, I hope this is an easy solution.

Sincerely, Michael

Replacing a style using ControlTemplate is not a bad solution on ListViewItem In fact, this would be my first choice.

Another way to complete the same type is to use the custom enclosure properties on your ListViewItem style:

  & lt; Style target type = "listviewItem" & gt; & Lt; Setter property = "Local: AddToInputBinding.Binding" & gt; & Lt; Setter.Value & gt; & Lt; Mousebinding gesture = "left wclick" command = "{binding doubleclick command}" /> & Lt; /Setter.Value> & Lt; / Setter & gt; ...  

To do this, you need to create MyBindingHandler.AddBinding Attached Properties:

  Public Category AddToInputBinding {Public Static InputBinding GetBinding (.. . // Prope snippets to use public static void Setbanding (... public static Reedonli dependency property BindingProperty = DependencyProperty.RegisterAttached ( "binding", Taipf (Inputbnding), Taipf (AddToInputBinding), new property Matdeta {PropertyChangedCallback = (obj, E) = & gt; {(UIElement) OGG. ((Inputbnding) e. Nuvalu);}}))}}  

It can be expanded to handle multiple binding, but you think: this class you any style inside allows connecting Inkutbing.

this solution is what you might be better off for it because DoubleClick binding is defined directly on Suchiboksaitim, another control within the template No. But I think it just comes in personal preference.

L

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -