2017-06-15 4 views
0

ページに50個のボタンがあるので、すべてのボタンに適用される境界線とIsPressed動作を宣言するStyleを宣言しました。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}" 

と完全に異なるビューモデルプロパティになるであろう結合別のボタンの背景として、別々のビューモデルのプロパティを介して制御されることです。

ボタンにスタイルを割り当てると、上記で宣言した背景設定は効果がありません。

すべてのボタンにスタイルを使用できますが、上記のようにバックグラウンドの値を宣言する方法はありますか?

+0

は助けるために言及したスタイルを貼り付け! –

答えて

1

あなたのConroleTemplateには、TemplateBindingによってTextBoxコントロールの元のBackgroundプロパティを尊重する必要があります。 テンプレートに記述されていないTextBoxプロパティ(凡例)は無意味になります。

そうに

Background="Transparent" 

を変更:今すぐ

Background="{TemplateBinding Background}" 

、背景がbackground TextBoxのプロパティの値によって影響を受けます。 とbackgroundプロパティにセットデフォルト値のため、セッターを経由してのスタイルで色を設定します。

<Setter Property="Background" Value="Transparent" /> 
+0

完了!よく働く!どうもありがとう! – chuckp

関連する問題