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
The developers have confirmed what I've been seeing. The carousel control was designed to navigate through each level one by one so it can't skip levels at will. They recommended that instead of trying to sync the tree with the carousel, the carousel's DataSource should be updated to point directly at the child items that wish to be viewed. So if the user drills down into the Tree and selects GRANT - 0, the XamDataCarousel DataSource should be bound to CHILD - 0's children collection so that GRANT - 0 will be seen in the carousel.
Hopefully that makes sense.
Okay thanks for the answer, wasnt the answer I was hoping for but I can work around it. Another question I have is the breadcrumbs, I can't seem to get the DataRecord word removed from my breadcrumb navigation, I've tried many things but can't seem to get it to work.
It follows on from this post: http://ko.infragistics.com/community/forums/t/27475.aspx
Any ideas on this?
Looking at the CarouselBreadcrumb control, we're just setting the Content property of this control to a DataRecord. The ToString() on a DataRecord is what shows the text you see. Since we're setting the Content you should be able to provide your own ContentTemplate to change the view. The DataContext for that template will be the CarouselBreadcrumb.Content which is that DataRecord. From there you can use a converter to configure the text however you like. Take a look at the example I attached.
Thanks for the example. this was actually the very first thing I tried and it didn't work for me. It works in the sample project you sent me however it does not work in my project. I am definitely using the same version of infragistics in my projects. I have even moved across my carousel control onto your sample project and it works.
It has been very frustrating but I have finally seen what the issue was. I was specifying the theme of the carousel as "Aero" in fact I have a combo box where the user can pick their theme and only certain themes work when trying to set the carousel breadcrumb content template. Very weird, unless the items you specify are "Default" or "PrintBasic" then it will not work. So in the example you sent me if you add this then you'll see:
<igDP:XamDataCarousel DataSource="{Binding Source={StaticResource dataUtil},
Path=CategoriesAndProducts}" Theme="Aero" />
Hopefully this can be fixed soon
Actually that would be expected. When you change the Theme on the control we're just adding a bunch of resources to the control level. One of these resources is a style for the CarouselBreadcrumb control. So since this style is lower in the tree (closer to the carousel control) than the one I declared in my sample, it will be used instead. To fix that you need to add the style to the XamDataCarousel.Resources. This will place the style lower in the tree making it the one that is used by the CarouselBreadcrumb.
<igDP:XamDataCarousel DataSource="{Binding Source={StaticResource dataUtil}, Path=CategoriesAndProducts}" Theme="Aero"> <igDP:XamDataCarousel.Resources> <Style TargetType="{x:Type igDP:CarouselBreadcrumb}"> <Setter Property="ContentTemplate"> <Setter.Value> <DataTemplate> <TextBlock Text="{Binding Converter={StaticResource converter}}"/> </DataTemplate> </Setter.Value> </Setter> </Style> </igDP:XamDataCarousel.Resources> </igDP:XamDataCarousel>
Great, thanks! I have no more issues
Thanks for your help
Grant