我在頁面上有50個按鈕,所以我聲明瞭一個樣式,它將聲明適用於所有按鈕的邊框和IsPressed行爲。WPF Button ...有沒有一種方法來獨立於樣式聲明設置背景顏色
<UserControl.Resources>
<statusModule:BooleanToBackgroundColorConverter x:Key="BooleanToBackgroundColor"/>
<Style x:Key="ValveButtonStyle" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border" Background="Transparent" BorderThickness="1" BorderBrush="Black">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsPressed" Value="True">
<Setter TargetName="border" Property="BorderThickness" Value="3" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
我的問題是,每個按鈕的背景顏色是通過一個單獨的視圖模型屬性控制,如
<Button Content="Deflection Gas Valve" Background="{Binding Path=OpenDeflectionGasValve, Converter={StaticResource BooleanToBackgroundColor}, Mode=OneWay}" Style="{StaticResource ValveButtonStyle}"
<Button Content="Purge Gas Valve" Background="{Binding Path=OpenPurgeGasValve, Converter={StaticResource BooleanToBackgroundColor}, Mode=OneWay}" Style="{StaticResource ValveButtonStyle}"
和另一個按鈕背景結合。將一個完全不同的視圖模型屬性。
如果我爲按鈕指定一個樣式,那麼上面聲明的背景設置不起作用。
有沒有一種方法可以使用所有按鈕的樣式,但是如上所示爲每個按鈕聲明一個背景值。
粘貼,以幫助提到的風格! –