In my apllication in each view I have a “shared” user control that each view loads. this control contains just four buttons, but I need to change the content of each button depending by the view who loads it.
No problem until the content is just a string, but I don’t know how to do once I need to put as a content of a button some controls, like a grid with images and text.
I tried creating a local resource with a key, but I need to set Content=”{DynamicResource res}”, so from ViewModel I cannot have any binding to the content…
<UserControl x:Class="PlusMatic.Presentation.Views.SubViews.FrontendButtonsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
d:DesignHeight="432" d:DesignWidth="211.2"
DataContext="{Binding FrontendButtons, Source={StaticResource Locator}}" >
<Grid x:Name="LayoutRoot" Margin="0,0,0,5">
<Grid.Resources>
<Border x:Key="ButtonOneStructure">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Source="{Binding FlagPath}" Stretch="Uniform" Margin="5"/>
<Viewbox Stretch="Uniform" Grid.Column="1" >
<TextBlock TextWrapping="Wrap" Style="{DynamicResource BigTextBlockPlusMatic}" >
<TextBlock.Inlines>
<Run Text="{DynamicResource 103ita}" />
<LineBreak />
<Run Text="{DynamicResource 103eng}" />
<LineBreak />
<Run Text="{DynamicResource 103fra}" />
<LineBreak />
<Run Text="{DynamicResource 103deu}" />
<LineBreak />
<Run Text="{DynamicResource 103esp}" />
</TextBlock.Inlines>
</TextBlock>
</Viewbox>
</Grid>
</Border>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="0.25*"/>
<RowDefinition Height="0.25*"/>
<RowDefinition Height="0.25*"/>
<RowDefinition Height="0.25*"/>
</Grid.RowDefinitions>
<Button x:Name="ButtonOne" Margin="0,5,10,5" Content="{DynamicResource ButtonOneStructure}" Grid.Row="0" Style="{DynamicResource FrontendButtonStyle}" />
<Button x:Name="ButtonTwo" Margin="0,5,10,5" Content="{Binding ButtonTwoContent}" Grid.Row="1" Style="{DynamicResource FrontendButtonStyle}" />
<Button x:Name="ButtonThree" Margin="0,5,10,5" Content="{Binding ButtonThreeContent}" Grid.Row="2" Style="{DynamicResource FrontendButtonStyle}" />
<Button x:Name="ButtonFour" Margin="0,5,10,5" Content="{Binding ButtonFourContent}" Grid.Row="3" Style="{DynamicResource FrontendButtonStyle}" />
</Grid>
Any help appreciated!
L.
Following the suggestion, I’ve choosen to implement it having one data template and a trigger inside which helps me to switch between two different controlTemplate:
By simply binding the boolean property “UseButtonOneLangChangeControlTemplate” in the dataTrigger from ViewModel I can change runtime the data template.
L