2017-06-03 5 views
1

プレスカラーとホバーカラーを使用したカスタムwpfボタンがありますが、いつも設定したくありません。ボタンの背景としてカラーのデフォルトカラーをホバーしますか? `wpfボタンでホバーカラーとプレスカラー、デフォルト値をバックグラウンドに設定する方法

public Brush HoverBackground 
     { 
      get { return (Brush)GetValue(HoverBackgroundProperty); } 
      set { SetValue(HoverBackgroundProperty, value); } 
     } 

     public static readonly DependencyProperty HoverBackgroundProperty = 
      DependencyProperty.Register("HoverBackground", typeof(Brush), typeof(CustomButton)); 

といくつかのカスタムpropertys

useage:Hoverbackgroundその後、<xx:CustomButton Background="xx"/>

: 私はちょうどこれをしたいすべての時間

<xx:CustomButton Background="xxx",HoverBacground="xx"/> 

これを書きたくはありませんバークグラウンドと同じになります

答えて

0

DPのメタデータにデフォルトを設定できます。

public static readonly DependencyProperty HoverBackgroundProperty = 
     DependencyProperty.Register("HoverBackground", 
            typeof(Brush), 
            typeof(CustomButton), 
            new UIPropertyMetadata(Brushes.Blue)); 
+0

私はこの新しいUIPropertyMetadata(背景)のように設定することはできません –

0

はそれを登録中BackgroundPropertyPropertyMetadataを設定し、メタデータにPropertyChangedCallbackを設定します。

BackgroundPropertyPropertyChangedCallbackには、HoverBckgroundPropertyの値を設定できます。

+0

私はこのメソッドを試してみましたが、それはHoverBackgroundが動作しないように設定します。 MSDNのドキュメントでは、プロパティにローカル値を設定するとバインドが削除される –

関連する問題