Hello community members!
In my solution I am using the xamtilemanager to administrate certain files. To delete or copy an item of the tiles i would like to bind the current selected item to my viewModel. If an Item is selected I want to execute delete or copy commands.
Unfortunatley I have not found a SelectedItem/SelectedValue or ActiveItem Property as it could be found eg in the xamdatagrid. Browsing the forum resources i found the following thread http://es.infragistics.com/community/forums/t/96889.aspx which uses an EventSetter for the PreviewMouseLeftButtonUp Event. Is this the only way to find out which tile was selected?Thank you for the information
Hello grubarec,
Thank you for your post.
Currently, the XamTileManager does not have any sort of SelectedItem/SelectedValue/ActiveItem functionality implemented on it. This can be implemented though, by extending the XamTileManager and adding a custom dependency property to keep track of the selected item and the XamTile that it corresponds to. Since this new property is a dependency property, you would be able to bind a data item in your view model to it.
By handling the PreviewMouseLeftButtonUp or the MouseLeftButtonUp event on the XamTiles, you can toggle their selection and use their Content property to get the data item that they represent. Then, you can set this particular data item to the SelectedItem property or remove it from the SelectedItem property if you wish to deselect it. Then, if that item becomes the selected item, you can apply a styling to the tile that corresponds to it. You can obtain this tile by using the XamTileManager.TileFromItem property.
From here, you can create a couple of ICommand derivations which you can use for your copy and delete commands. If you pass your custom XamTileManager to these commands as the CommandParameter, you can check this newly created SelectedItem property and add or remove this item from the collection that makes up the ItemsSource of your XamTileManager if you are using one.
I have attached a sample project demonstrating a way that this could be achieved. I hope this helps you.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate DeveloperInfragistics Inc.www.infragistics.com/support
Hello Andrew!
Thank you for the sample. It worked like a charm and helped me a lot to achieve the functionality i wanted.
Hello Andreas,
I have modified the sample project that I had originally sent you to remove the hook into the XamTile.MouseLeftButtonUp event in the CustomTileManager.Loaded event in favor of a Style for XamTile that uses an EventSetter for the MouseLeftButtonUp event. This ensures that the event will fire for each XamTile that exists within this derivation of the XamTileManager, and eliminates the need for the timer that you are currently using.
In the event handler for the XamTile.MouseLeftButtonUp event invoked by this event setter, I would simply recommend that you cast the sender to a XamTile, and get the data item from the tile.Content property. Then, you can check if that data item is the "SelectedItem" of your custom tile manager. If it is, then set the tile manager's selected item to null. If it isn't, you can set the tile manager's selected item to that data item. The property changed callback for the custom selected item dependency property will handle the rest; on terms of styling the XamTile that represents the selected item.
I have attached the modified sample project to this post. I hope this helps you.
Thank you for the sample. It is working as long as you are not applying any other themes. One of the requirements my CTO gave me, is to change the theme during the runtime. But as soon as a style is created for the xamtile, the theme is no longer applied to the xamtile. Attached please find the modified sample. By clicking on the buttons the theme is changed during the runtime as you will see on the buttons and the xamtilemanager but not on the xamtile. Do you think there will be a solution to handle the changed themes with the xamtile MouseLeftButtonUp?
SincerelyAndreas
I have been investigating into this issue you are seeing, and it seems that the functionality of changing the theme being included here changes a few things. It appears that what is happening here is that the styles with respect to the templates of the XamTiles are still getting applied, but the background colors are being ignored due to the XamTile style written in the custom XamTileManager.Resources section. I had also thought to recommend binding the XamTile's Background property to a brush that would be set differently based on the application theme, but this doesn't appear to be working in practice, since the XamTile objects being used are being recycled due to the virtualization in effect, and so the bound brush is only going into effect on certain tiles, while others retain their previous styling.
If you want to continue using the EventSetter for the XamTile's MouseLeftButtonUp event in this case, I would recommend creating a new ResourceDictionary in your project for each of the different themes you are looking to apply. From here, I would recommend navigating to the default Theme styles folder, which can commonly be found at the following directory: C:\Program Files (x86)\Infragistics\2015.2\WPF\Themes. Each theme that you are currently applying in your sample project will be listed there.
Rather than keeping the implicit style reference for XamTile in your custom XamTileManager.Resources section, I would recommend going into each of the theme folders that you see in the above directory, and navigate to the "ThemeName.xamTileManager.xaml" folder. In here, you will find the default styles for the XamTiles for each particular theme. You can then copy these XamTile styles and their dependencies over to your resource dictionaries in your project, add the EventSetters to them and then programmatically merge them with your custom XamTileManager.Resources section when you change your application theme to a new theme. The contents of the event handlers in your ResourceDictionary code-behind files will be the same as in the sample project you sent me, except you will not be able to access the custom XamTileManager by name. Instead, I would recommend using the Infragistics.Windows.Utilities class and its method GetAncestorFromName to get the tile manager by name by searching the visual tree of your application. The code to do this would look like: Utilities.GetAncestorFromName(clickedTile, "NameOfCustomTileManager");
I hope this helps you. Please let me know if you have any other questions or concerns on this matter.
Do you have some information for me about the "unselected Item"?
Thank you for the information.
I apologize for the delay in my response.
I see the behavior you are referring to by switching to the Metro theme in the sample project that you have provided me. The first selected tile in the XamTileManager is not becoming transparent when deselected. It is simply being colored white. You can see this happening in the static SelectedItemChanged method of the CustomTileManager class. Note the section within this piece of code: "if (e.OldValue != null).
In that particular piece of code, the deselected tile's Background property gets set to the NotSelectedBrush, which, in the case of the current sample project, is a SolidColorBrush with its color set to White. If you were to set this color to something else, I do not believe you would see this issue occurring.