C#ボタンスタイルに複数のContentPresenter(Windows 8.1)
-
21-12-2019 - |
質問
カスタムスタイルを使用して、ボタンに2つのデータを表示しようとしています。
だから、私は以下のようなXAMLコードを1つの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>
.
そして私はこのようなこのスタイルを使います。
<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}"/>
.
その後、このボタンはこの
のように見えますとにかく、スタイルにもう1つの「ContentPresenter」を追加し、ボタンにもう1つの異なるデータを表示します。
しかし、もう1つの「ContentPresenter」をスタイルに追加する場合は、「ContentPresenter」に2つの異なるデータを割り当てる方法がわかりません。 '
これは私が作りたいものです。
事前感あり
解決
ボタンのTag
プロパティを使用して追加のデータを割り当て、次のように2番目のContentPresenter
Content
をバインドできます。
<ContentPresenter
Grid.Row="1"
Content="{TemplateBinding Tag}"
HorizontalAlignment="Center"
VerticalAlignment="Center">
</ContentPresenter>
.
およびButton
:
<Button Tag="{Binding OTHERDATAPROPERTY}" Content="{Binding Comments}"></Button>
. 所属していません StackOverflow