Hi,
I need to be able to double click on a carousel item however it needs to follow the mvvm pattern.
Thanks, Grant
Hi Grant,
A Behavior<T> is probably your best option. You can create a Behavior<T> where T is the XamCarousel. Inside the behavior you can handle the PreviewMouseDoubleClick event on the XamCarousel and perform whatever logic you need. If you need something executed in your view model you can add an ICommand to the behavior as a DependencyProperty and then manually execute it when the double click occurs, passing whatever information along that is required. Then when you create the behavior you can bind to a command in the view model.
(I tried searching for an MSDN article that shows an example Behavior<T> but I can't find anything so here is a pretty good example that shows how to code a Behavior and use it on a control in XAML.)
In the double click event you'll want to make sure that the mouse is contained inside a DataRecordPresenter before continuing with your logic. DataRecordPresenter is the UI element which defines a carousel item. Inside the Infragistics.Windows namespace there is a class called Utilities. This class contains a bunch of static helper methods and one of them lets you traverse the visual tree a bit easier than using the VisualTreeHelper. Use the method called GetAncestorFromType() in order to find out if the user double clicked inside a DataRecordPresenter.
var record = Infragistics.Windows.Utilities.GetAncestorFromType(e.OriginalSource as DependencyObject, typeof(DataRecordPresenter), false);if (record != null){ // user double clicked on a carousel item}
Let me know if you have any questions.
Thanks for the reply, I did just look into doing this but I think I'm creating more work for myself. The issue comes down to the fact that I cannot seem to keep my two UI lists in sync. So let me explain what it is, I have a TreeView on the right hand side of the application and a carousel on the left. Both have hierarchical data and both should be kept in sync as they are sharing the selected item property. However if the treeview it expanded to the lowest child then the carousel cannot select the correct item.
The user needs to be able to navigate through the list using the treeview and the carousel.
Also if the treeview selects the root node after the lowest child has been selected the carousel cannot handle this either, I appreciate this may be confusing so I'll upload a sample project, Hopefully there's a way around this.
I've been stuck on it for the past couple of days, please help