Consider the following bit of code:
```
DataTemplate x:Key="NormalTemplate"> <Button Command="{Binding Path=QueryServiceCommand}" Content ="Query service"> <ig:Commanding.Command> <igPrim:TileCommandSource EventName="Click" CommandType="ToggleMaximized" AllowEventHandling="False" /> </ig:Commanding.Command> </Button> </DataTemplate> <DataTemplate x:Key="MaximizedTemplate"> <TextBlock Text="Max"></TextBlock> </DataTemplate> <DataTemplate x:Key="MinimizedTemplate"> <TextBlock Text="Min" /> </DataTemplate> <DataTemplate x:Key="MinimizedExpandedTemplate"> <TextBlock Text="MinExpanded" /> </DataTemplate> <DataTemplate DataType="{x:Type viewModels:HomeViewModel}" > <Grid> <ig:XamTileManager Name="XamTileManager" ItemsSource="{Binding Apps}" ItemTemplate="{StaticResource NormalTemplate}" ItemTemplateMaximized="{StaticResource MaximizedTemplate}" ItemTemplateMinimized="{StaticResource MinimizedTemplate}" ItemTemplateMinimizedExpanded="{StaticResource MinimizedExpandedTemplate}"/>
This results is a `XamTileManager` with _n_ number of XamTiles each in Normal mode displaying a button with text "Query Service". Click the button, and the tile switches to Maximize mode (the text Max is displayed on the tile). You can go back to normal mode just fine by clicking the maximize button on top right.
However, the QueryServiceCommand's Execute method is never called.
However, remove `ItemTemplateMaximized="{StaticResource MaximizedTemplate}"` and the command executes just fine and tile Maximizes too, i.e. in:
<DataTemplate x:Key="NormalTemplate"> <Button Command="{Binding Path=QueryServiceCommand}" Content ="Query service"> <ig:Commanding.Command> <igPrim:TileCommandSource EventName="Click" CommandType="ToggleMaximized" AllowEventHandling="False" /> </ig:Commanding.Command> </Button> </DataTemplate> <DataTemplate x:Key="MaximizedTemplate"> <TextBlock Text="Max"></TextBlock> </DataTemplate> <DataTemplate x:Key="MinimizedTemplate"> <TextBlock Text="Min" /> </DataTemplate> <DataTemplate x:Key="MinimizedExpandedTemplate"> <TextBlock Text="MinExpanded" /> </DataTemplate> <DataTemplate DataType="{x:Type viewModels:HomeViewModel}" > <Grid> <ig:XamTileManager Name="XamTileManager" ItemsSource="{Binding Apps}" ItemTemplate="{StaticResource NormalTemplate}" ItemTemplateMinimized="{StaticResource MinimizedTemplate}" ItemTemplateMinimizedExpanded="{StaticResource MinimizedExpandedTemplate}"/>
`QueryServiceCommand.Execute()` is called and the tile Maximizes.
I think the problem is that the `TileCommand` which gets executed by the Click event sets the routed event to Handled which means the Button's Command never gets executed. Though this does not explain the strange behavior observed by removing the Maximize template. Any thoughts on what's happening here?
I've tried:
```<igPrim:TileCommandSource EventName="MouseUp" CommandType="ToggleMaximized" AllowEventHandling="False" />````
but that doesn't Maximize the XamTile.
Thanks!
Hello Asad,
I have been investigating into this issue, and I have reproduced the behavior you are seeing, but I am not entirely sure exactly what is causing it just yet. I have a theory that it is not the command marking the button's Click event as handled, but instead that the ItemTemplateMaximized template is taking over, and so when the button goes to fire its actual Command, that button no longer exists and so the command is not fired. This is only a theory at the moment, though, and I am not entirely sure.
I am going to investigate into this issue a bit further, and I hope to have more information for you on this matter soon. Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
I have been testing against the XamTileManager's source code, and it appears that my above theory was correct, and that the command for the XamTileManager is taking precedent over the one that is bound to the Button's Command property, so by the time the button actually goes to fire its actual Command, the tile is maximized. This means that the DataTemplate that contains the button is no longer used, and so the button's Command is never fired.
As a workaround to this, I would recommend that you pass the XamTile that the Button belongs to as the CommandParameter. You can do this using a RelativeSource AncestorType binding for the type of XamTile. At the end of the logic that you are performing in your command, you can make a call to the ExecuteCommand method of the XamTile to toggle the maximized state of the XamTile that the button is housed in:
XamTile tile = parameter as XamTile;tile.ExecuteCommand(TileCommandType.ToggleMaximized, null, null);
I have attached a sample project to demonstrate the above. I hope this helps you.
Please let me know if you have any other questions or concerns on this matter.
Hi Andrew
I came to the same conclusion after I had posted here, the button is gone before it can execute. Thanks for the workaround, I can do with that for now. Look forward to the fix in the next release
Cheers,Asad
I apologize, but this isn't a bug, and there isn't a fix planned for this.
This behavior is expected, as the TileCommandSource is taking priority over the actual Command that is bound to the button, and since a separate template is being used for the ItemTemplateMaximized, that template is being applied from the TileCommandSource's command. This happens before the Button ever gets to the code that should fire its Command, and by the time that it would, the containing template is no longer used, and so that code is not fired.
If you wish to have a TileCommandSource and a separate command bound to your Button in this case, I would recommend continuing with the proposed workaround to the above behavior.