我已經設計了一個Button
元素,其中包含兩個TextBlock
s。一個帶有實際文字,另一個帶有一個圖標(來自Segoe UI Symbol)。帶有多個TextBlocks的XAML樣式按鈕
這是風格的代碼:
<Style x:Key="ButtonSettingsStyle" TargetType="Button">
<Setter Property="Content" Value=""/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<StackPanel Background="Transparent" Orientation="Horizontal" Height="60">
<VisualStateManager.VisualStateGroups>
...
</VisualStateManager.VisualStateGroups>
<TextBlock
x:Name="Icon"
Text=""
Margin="10,0,5,0"
Width="40"
Foreground="{TemplateBinding Foreground}"
FontSize="32"
VerticalAlignment="Center"
RenderTransformOrigin="0.5,0.5"
FontFamily="Segoe UI Symbol"></TextBlock>
<TextBlock
x:Name="Text"
Text="{TemplateBinding Content}"
VerticalAlignment="Center"
Style="{StaticResource TextBlockListBoldItem}"
Foreground="{TemplateBinding Foreground}" />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
問題:
我也希望圖標的TextBlock有一個自定義圖標,因此定製Text
- 特性和使用也許這樣(我真的不知道這應該如何工作):
<Button Style="{StaticResource ButtonSettingsStyle}" Content="Settings" IconContent="" />
我該如何做到這一點? Content
-Setter已經分配給Text-TextBlock ...
感謝您的幫助!
不要忘記調整好的模板... – meilke
另外,你不需要構造函數。在這種簡單的情況下,'Button'將完成所需的一切。 – meilke
感謝您對我的回答建議的編輯:但您可以使用'{TemplateBinding bla}'和'{Binding bla,RelativeSource = {RelativeSource TemplatedParent}}' – meilke