2017-07-04 115 views
1

我想着色WPF應用程序中的複選框。我試圖在XAML中鍵入此:着色wpf複選框C#

<CheckBox x:Name="topintegral" Content="TOP Integral" `enter code here` 
      RenderTransformOrigin="0.5,0.5" Width="188" Margin="94,105,68,86" 
      FontWeight="Bold" FontSize="15" Background="Black" 
      MouseEnter="MouseFocus" MouseLeave="MouseLeave" BorderBrush="#FFE6FFFF"> 

,並在.cs文件:

private void MouseFocus(object sender, MouseEventArgs e) 
{ 
    topintegral.Background = new SolidColorBrush(Colors.White); 
} 

但它表明這樣的:

enter image description here

+0

你期待什麼結果? – mm8

回答

0

如果你想它放回之前的狀態(黑色),然後在MouseLeave事件中執行。

private void MouseLeave(object sender, MouseEventArgs e) 
    { 
     topintegral.Background = new SolidColorBrush(Colors.Black); 
    } 

否則,你的代碼工作正常。

MouseFocus方法是MouseEnter事件的事件處理程序,所以當光標進入複選框時它變成白色。但是如果你想讓它回到以前的顏色,只需編寫MouseLeave事件的事件處理程序即可。