Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
665
Double click on carousel item
posted

Hi,

I need to be able to double click on a carousel item however it needs to follow the mvvm pattern.

Thanks, Grant

Parents
No Data
Reply
  • 34510
    Offline posted


    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.

Children