0

私は WPF でオブジェクトを作成し、そのためのイベントをフックButtonしました。MouseEnterMouseEnterButtonBackground

Button button = new Button();  
button.Background = Brushes.Red;  
button.BorderBrush=Brushes.Red;  
button.MouseEnter += new MouseEventHandler(button_MouseEnter);`

そして私のイベントは:

private void button_MouseEnter(object sender, MouseEventArgs e)
{
    Button button = sender as Button;
    button.Background = Brushes.Yellow;
    button.BorderBrush = Brushes.Yellow;
}

イベントでボタンをBorderBrush変更しましたが、背景が機能せず、代わりにイベントでデフォルトの灰色に変わります。MouseEnterButtonBackgroundMouseEnter

どこが間違っているのでしょうか、誰か助けてください。

4

2 に答える 2

0

デフォルトの wpf スタイル テンプレートには、マウスオーバー効果を処理するトリガーが含まれています。これがハンドラーに干渉していると思います。ボタンにトリガーのないスタイルを設定してみてください (ところで、これは使用すべき wpf の方法であり、コード ビハインドではなくテンプレートを使用してコントロールをスタイル設定します)、コードが機能するかどうかを確認します。

于 2013-07-15T07:10:11.590 に答える