I have a style defined for XamTile as follows:
<Style TargetType="ig:XamTile" x:Key="fistyle"> <Setter Property="IsMaximized" Value="{Binding Selected,Mode=TwoWay}"/> </Style>Within the XamTileManager this style is being set as the ItemContainerStyle. The theory is that as I add new items to the TileManager I can set Selected=true on the items viewmodel to make the new tile Maximzed.
Unfortunately, it doesn't work. There are no binding errors and I have confirmed the Style is applied. (I set IsHitTestVisible=False in the style to test it).
Hi Amatul,
My statement about using the ItemContainerStyle may have mislead you. I meant that you could use ItemContainerStyle for Tile appearance, not for maximizing the tile, because ItemContainerStyle applies to all tiles and you cannot set all tiles maximized. For initial load you can bind the Tile's IsMaximized proprty to your view model, and when you add new tile, since that is implemented is in code you need to reference the IsMaximized setter in code. You mentioned that you were using button command adding new tiles, and that's done in code I assume, and if the new tile needs to be maximized at that time, then you need to reference the IsMaximized setter in code.
If you can show me, possibly with code, how exactly you are adding new tiles, I will see what else we can do in XAML if possible.
Thanks,
Sam
Hi Sam,
Thanks a lot for such a quick reply. Yes, my object implements INotifyPropertyChanged interface.
I tried to change the sample you provided to use ItemContainerStyle to set IsMaximized. But it is not working. I have attached the modified version here. Could you please tell me what is wrong there? Also, It will be great if you provide a working version.
Amatul
I used the Style as one way of applying the Setter with IsMaximized property. It was not intended for the Tile's appearance. Sure you can use the ItemContainerStyle for that matter, and it's not limitted to be done in code behind either. It can be done in XAML.
As far as binding the Tile's IsMaximized property to your view model's IsMaximized property, you can do it in XAML, but keep in mind that any changes to your view model's property won't be propegated to the binding unless your object implements INotifyPropertyChanged interface.
IsMaximized="{Binding Path=isMaximized}
I have looked at the sample. It is working fine. Now my question is:
Just to clarify the context, In my case, I use a command to handle the button click. The command is in the view model. So I do not want to access view's content (tile) at view model. I have a IsMaximized property in the view model. All we need to bind the IsMaximided property of the tile to the view model 's property. It is best for me if I can do the binding in XAML.
Hello Mikael,
This approach was intended for one-way binding. When you change the source to which the style is bound to, the new added tiles will not get the maximized state as they are based on the property value in the style.
This was only for new added tiles. It could be applied to the tiles in general, because only one tile at a time can be in maximized state.
If you can attach a code for me to see, or explain how you are trying to monitor the visual state of the tiles in your view model, I may be able to make a suggestion, but this approach may not be what you are looking for.
Thank you,