1
這裏內邊框背景是在我的應用程序資源的XAML,全球改變了所有的Button控件的應用程序的外觀和行爲像我想:更改支持算法FMP的ControlTemplate
<Style TargetType="{x:Type Button}" x:Key="MyButtonStyle">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border x:Name="Border" CornerRadius="0" BorderThickness="0"
Background="CornflowerBlue" BorderBrush="CornflowerBlue">
<ContentPresenter Margin="2" HorizontalAlignment="Center" VerticalAlignment="Center" RecognizesAccessKey="True" />
</Border>
<ControlTemplate.Triggers>
<!-- a bunch o' triggers here -->
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
在我的應用程序的一個用戶控件,我想改變這個按鈕的一些屬性。下面是一些XAML,我使用的UserControl.Resources部分現在要做到這一點:
<Style x:Key="SpecialButton" TargetType="Button" BasedOn="{StaticResource MyButtonStyle}">
<Setter Property="Width" Value="20" />
<Setter Property="Visibility" Value="Collapsed" />
<Setter Property="Content" Value=">" />
<Setter Property="Border" Value="#eeeeee" />
<Setter Property="Border.Background" Value="#eeeeee" />
</Style>
,我的風格分配給SpecialButton有正確的寬度,可見性和內容上我的用戶控制按鈕,但最後兩次嘗試不起作用。我將如何去改變這個SpecialButton風格中來自應用程序資源名稱爲「Border」的Border的背景顏色?
感謝您的回答,它不完全正確,但它導致我走向正確的道路。我原來的問題在第一個XAML代碼片段中的Style元素上有一個'x:Key',這不在我的應用程序的XAML中。因此,我不得不在我的第二個XAML代碼片段中使用'BasedOn =「{StaticResource {x:Type Button}}」'來讓它尊重對原始樣式的更改。 –