Hi
Can you show me how to accomplish this? I think I need to set a DataTemplateSelector and have each DataTemplate a UserControl. Also I would like to bind each UserControl's data to a different ViewModel.
Thanks!
Hello Marlon,
Thank you for your post. I have been looking into it and since the XamTileManager doesn’t have TemplateSelector I used another approach to achieve this functionality. I created a DataTemplate with two controls (Button and TextBlock) and based on value in the ViewModel only one of them is shown in the different Tiles. Please let me know if this helps you or you have further questions on this matter.
Looking forward for your reply.
That is not quite what I need. Can you create a sample app that does something like this?
Thank you.
<UserControl x:Class="WpfApplication1.ImageTextControl">
<Grid>
<ig:XamTileManager Name="xamTileManager1" >
<ig:XamTileManager.Resources>
<DataTemplate x:Key="ImagesTemplate">
<StackPanel>
<!--I want to bind ColorImage to PhotoViewModel.ColorPhotoFileUri-->
<Image x:Key="ColorImage"
Source="{Binding ColorPhotoFileUri}"
Stretch="Fill" />
<!--I want to bind BlackWhiteImage to PhotoViewModel.BlackWhitePhotoFileUri-->
<Image x:Key="BlackWhiteImage"
Source="{Binding BlackWhitePhotoFileUri}"
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="TextTemplate">
<!--I want to bind to TextViewModel.FieldLabel-->
<TextBlock x:Name="FieldLabelText"
Text="{Binding FieldLabel}"
Grid.Column="0"/>
<!--I want to bind FieldValueText to TextViewModel.FieldValue-->
<TextBlock x:Name="FieldValueText"
Text="{Binding FieldValue}"
Grid.Column="1"/>
<data:ControlTemplateSelector x:Key="ImagesTemplateSelector"
ImagesTemplate="{StaticResource ImagesTemplate}"
TextTemplate="{StaticResource TextTemplate}" />
</ig:XamTileManager.Resources>
<ig:XamTileManager.ItemTemplateMaximized>
<DataTemplate>
<ContentPresenter Content="{Binding}" ContentTemplateSelector="{StaticResource ControlTemplateSelector}"/>
</ig:XamTileManager.ItemTemplateMaximized>
</ig:XamTileManager>
</Grid>
</UserControl>
I have modified the sample I sent you before, so now it has a ContentControl as ItemTemplate and I created a TemplateSelector for the ContentControl in order to achieve the functionality you want. Please let me know if this helps you or you have further questions on this matter.
Hi Stefan,
Thank you for your response. However I already have a DataTemplate and TemplateSelector in my xaml file. What I need is to assign each DataTemplate's DataContext to a different ViewModel in xaml. Such that the UI elements in each DataTemplate binds to their corresponding ViewModel Properties.
Thank you,
-Marlon
Could you please send a sample with your data structure and screenshot of the desired results and also could you please tell me why you want to have different view models rather than have one that combine them?