Reputation: 67
I'm trying to display 2 data on a button, using custom style.
So, I wrote an XAML code like below, with one 'ContentPresenter.'
<Style x:Key="Num_of_Comments" TargetType="Button">
<Setter Property="Foreground" Value="{ThemeResource AppBarItemForegroundThemeBrush}"/>
<Setter Property="VerticalAlignment" Value="Top"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/>
<Setter Property="FontWeight" Value="Normal"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid Background="Transparent" x:Name="RootGrid">
<Grid
Height="42"
Width="42">
<Ellipse
x:Name="Ellipse"
Fill="{ThemeResource AppBarItemBackgroundThemeBrush}"
Stroke="{TemplateBinding Foreground}"
StrokeThickness="2"
UseLayoutRounding="False" />
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="21"/>
<RowDefinition Height="21"/>
</Grid.RowDefinitions>
<ContentPresenter
Grid.Row="0"
Foreground="{TemplateBinding Foreground}"
HorizontalAlignment="Center"
VerticalAlignment="Center">
</ContentPresenter>
</Grid>
</Grid>
<Rectangle x:Name="FocusVisualWhite" IsHitTestVisible="False" Opacity="0" StrokeDashOffset="1.5" StrokeEndLineCap="Square" Stroke="{ThemeResource FocusVisualWhiteStrokeThemeBrush}" StrokeDashArray="1,1"/>
<Rectangle x:Name="FocusVisualBlack" IsHitTestVisible="False" Opacity="0" StrokeDashOffset="0.5" StrokeEndLineCap="Square" Stroke="{ThemeResource FocusVisualBlackStrokeThemeBrush}" StrokeDashArray="1,1"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
And I use this style like this.
<Button Grid.Column="1" Content="{Binding Comments}" Style="{StaticResource Num_of_Comments}" IsEnabled="False" Margin="10,0,0,0" VerticalAlignment="Center" Foreground="{Binding Comments_color}"/>
Then, this button looks like this
Anyway, I'd like to add one more 'ContentPresenter' in the style, and display one more different data on the button.
But if I add one more 'ContentPresenter' into the style, I don't know how to assign 2 different data on each 'ContentPresenter.'
This is the button what I want to make.
Thanks in advance
Upvotes: 1
Views: 896
Reputation: 18580
You can use Tag
property on button to assign additional data and bind the second ContentPresenter
Content
as follows:
<ContentPresenter
Grid.Row="1"
Content="{TemplateBinding Tag}"
HorizontalAlignment="Center"
VerticalAlignment="Center">
</ContentPresenter>
and on Button
:
<Button Tag="{Binding OTHERDATAPROPERTY}" Content="{Binding Comments}"></Button>
Upvotes: 2