2017-07-04 72 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事件的事件处理程序即可。