Hi,
I am trying to write a Prism (CAL) adapter for the XamTilesControl, and in my implementation I would like to have only one active tile, and this tile should be the one and only maximized tile. So, maximizing a tile should make it's view active (easily handled by hooking into the TileStateChanged event), and when the view is made active programmatically then the tile should be maximized, and that's where I run into problems.
When a new view is added to the prism region, I add it to the tile control, then I attempt to get the tile by calling TileFromItem(), but this returns null. :( After reading some other posts I tried calling UpdateLayout() first, but that didn't help, but after a little more reading I found another suggestion to use Dispatcher.BeginInvoke(). In the end I had to use the following code (_instance is my XamTilesControl):
_instance.Dispatcher.BeginInvoke((Action)(() => { _instance.UpdateLayout(); Tile tile = _instance.TileFromItem(e.NewItems[0]); if (tile != null) { tile.State = TileState.Maximized; } }));
This did allow me to access the Tile for the view, and to set it's state to Maximized, but unfortunately it doesn't actually maximize the view! Instead the view appears to be still in normal mode, but it does have a minimize button (as opposed to a maximize button when I don't set the tile state to Maximized), which implies that the tile thinks it's maximized! If I click the button it changes to a Maximize button and the tile remains the same, when I click it again it maximizes.
So I have two problems, first I would like to know the proper way to obtain the Tile after adding an item to the Items collection, and second I would like know how to maximize the tile programmatically. If anyone has any ideas I would be very grateful.
Thanks.
Brian
Hi Brian,
Glad I could help and thanks for posting your solution code here for the next person.
Please let me know if you have any further questions.
Hi Marianne,
Thanks for the info, I hadn't realized that I could just bind to the Header property! :) I have solved my problem with the code below:
// NB: This would be a reference to the actual user controlUserControl myControl = new UserControl();
// configure binding for headerBinding bind = new Binding("DisplayName");bind.Source = myControl.DataContext;bind.Mode = BindingMode.OneWay;
// add control to a new tileTile tile = new Tile() { Content = myControl };
// set binding for Headertile.SetBinding(Tile.HeaderProperty, bind);
// add tile to tiles controltilesControl.Items.Add(tile);
Thanks for your help.
The HeaderPathProperty is the xamTilesControls’ dependency property for setting the path to a value in the source that will be used to initialize the Header of each Tile and you can bind to it. I’m guessing that you set the HeaderPath in code.
The tiles also have a HeaderProperty which is a dependency property. You can also set each tile's header as I did in my snippet when I add a single tile.
I think the question is how are you setting / binding to this property? Or are you binding to this property? You should be able to set the HeaderPath or Header of each tile.
I just noticed that the headers of my tiles are no longer displaying the header text. Previously I had set the HeaderPath property of teh XamTilesControl to specify which property on my user control to bind to for this text, but this does not appear to work when you add Tile items directly. :(
I have had to modify my adapter class to set each Tile's Header explicitly, and to do that meant I had to use a cast to convert it's contained user control's DataContext to my view model type, which makes it more tightly coupled than I would like. :(
Is there a way to have the Tile bind it's Header to a property of it's Content object, possibly by specifying a HeaderPath as the XamTilesControl does?
Thanks,
Thank you for the update. Please let me know if I can be of further assistance.