在我的C#/ WPF/.NET 4.5應用程序,我有按鈕與我在下面的方式來實現圖片:的樣式WPF的按鈕與圖片+文字
<Button Style="{StaticResource BigButton}">
<StackPanel>
<Image Source="Images/Buttons/bt_big_save.png" />
<TextBlock>save</TextBlock>
</StackPanel>
</Button>
我有資源字典UIStyles.xaml中,我聲明如下:
<Style TargetType="Button" x:Key="BigButton">
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Height" Value="80" />
<Setter Property="Width" Value="80" />
<Setter Property="Foreground" Value="White" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border x:Name="border"
CornerRadius="5"
Background="#FF415360">
<ContentPresenter x:Name="ButtonContentPresenter"
VerticalAlignment="Center"
HorizontalAlignment="Center">
<ContentPresenter.Resources>
<Style TargetType="TextBlock">
<Setter Property="TextAlignment" Value="Center" />
</Style>
<Style TargetType="Image">
<Setter Property="Width" Value="10" />
<Setter Property="Margin" Value="10" />
</Style>
</ContentPresenter.Resources>
</ContentPresenter>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
光標,高度,邊框等性能做工精細,但我不能樣式的TextBlock
和Image
。
具體來說,有什麼需要是這樣的:
最終看起來像這樣(不考慮色差):
我見過similar questions問前但解決方案使用了不同的方法(我不想創建自定義的用戶控件,除了這一個之外,我的所有需求都包含在本代碼中並且重寫將是一個滋擾)。我只是需要修復我的Style
使得TextBlock
居中和Image
居中且變得更小。
如何重寫Style
來糾正按鈕的外觀?
這是正確的,''中的樣式沒有得到應用。將它們移動到「」使UI看起來像預期的那樣。 –
Rachel