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://ko.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.
Sorry, that I had to remove the Reply tag, but I have found some issues about the selection mode.
Attached please find the modified sample in which I load 100 elements (numbers only, no names as this should be enough for the sample) into the tilemanager and I made the template a little bit bigger.
After the start I see the first 26 elements.
1) If the scroll bar is moved to the right, I can click on any tile, but the selectedItem is not called. I think this is an issue of the virtualization. So I tried
<ig:NormalModeSettings ShowAllTiles="true" />
When this option is set, all tiles are displayed and could be selected. However, the compression is no option for me.2) When any tile is maximized, the other tiles are loaded into the right next to the tileSplitter. The first items in the list could be still selected, but scrolling down the list, the other tiles are no longer selectable. 3) After I minimized the current maximized window, other tiles are still not selectable.
I have already added handlers for mouse, touch and stylus "enter" and "move" events to enable the selection mode again. This maked the screen flickr when the mouse enters the tilemanager area. Which handlers do I have to add for the Tile maximization and minimization so that the selection is enabled again?As I said already, the ShowAllTiles="true" property is no option for me, how can i still set the selection mode for all tiles if the virtualization is enabled?Are there any events if the scrollbar is moved in one direction so that I can add methods to those events where I set the selection mode?
Thank you for you help
After some test, I found that I could add the TileStateChanging event to set the missing item selections.
If the NewState Property of the TileStateChangingEventArgs is set to TileState.Normal, I start a timer. The timer event than adds the eventhandlers for the separate tiles. I added the timer, as in the TileStateChanging Event, not all tiles are set.
Hello Again!
Attached please find the sample solution
I believe the issue you were seeing was being caused due to the virtualization of the tiles that were out of view. When you set the initial mouse event on the tiles when the XamTileManager loaded, you were setting them on each of the tiles, but those tiles get recreated or recycled when they scroll into view. This is why the mouse event wasn't working on all of the tiles after scrolling the XamTileManager.
It appears that your most recent sample project solves this issue, but you may see performance issues with this solution in the long run. Rather than hooking and unhooking the MouseLeftButtonUp event on a timer, you may want to use a Style for XamTile that hooks into the MouseLeftButtonUp event via an EventSetter. This way, you can ensure that this event will fire for all tiles in your XamTileManager. You also may be able to use a trigger in this style and reference the SelectedItem property of your custom XamTileManager against the content of your XamTiles to place the "selected" background color on the tile.
I am currently working on a sample to demonstrate this to you, as I do believe there is a better way to achieve this requirement than what is currently being used.
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.
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.
Do you have some information for me about the "unselected Item"?
Thank you for the information.
Thank you for your help so far. Attached please find the modified example with the left button up event in the theme resource files.
There is one issue left, if I select on tile and then another tile, the border and header color of the first selected tile becomes transparent. So it is hard to identify the unselected tile.Have I missed something?
Thank you for your helpAndreas
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.
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