简体   繁体   English

Chnage Telerik WPF按钮颜色通过代码

[英]Chnage Telerik WPF button color via code

I learning WPF and build an simple application. 我学习WPF并构建一个简单的应用程序。 This is my button: 这是我的按钮:

<Button x:Name="btnAddFiles" Content="Add" HorizontalAlignment="Left" Margin="1046,34,0,0" VerticalAlignment="Top" 
        Width="111" Height="34" FontSize="20" Foreground="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}" 
        Background="{x:Null}" MouseEnter="btnAddFiles_MouseEnter" BorderBrush="Transparent" />

And this is how it looks like: 这是这样的:

http://s27.postimg.org/h0iq4mrrz/image.png http://s27.postimg.org/h0iq4mrrz/image.png

I have changed the button background color to Transparent so the background color the you see is all my application background color. 我已将按钮背景色更改为“ Transparent因此您看到的背景色就是我所有应用程序的背景色。 All i want to do is when the mouse is over the button change the background color to Transparent . 我要做的就是当鼠标悬停在按钮上方时,将背景色更改为Transparent Currently this is the current when mouse is over: 当前,这是鼠标悬停时的当前状态:

http://s30.postimg.org/x61ssujnx/image.png?noCache=1411485462 http://s30.postimg.org/x61ssujnx/image.png?noCache=1411485462

So i registered to MouseEnter event : 所以我注册了MouseEnter event

private void btnAddFiles_MouseEnter(object sender, MouseEventArgs e)
{
    //btnAddFiles.Background = // change the color
}

But i can see that btnAddFiles.Background require Brush and nor Color Any idea hot to change it ? 但是我可以看到btnAddFiles.Background要求使用BrushColor进行更改吗?

i couldn't see your pictures but this is how we change back color in wpf: 我看不到您的图片,但这是我们在wpf中更改回色的方式:

btnAddFiles.Background = Brushes.Transparent;

and you can use your code in a mouse enter and mouse leave event. 您可以在鼠标进入和鼠标离开事件中使用您的代码。

1st Edit 第一次编辑

private void btnAddFiles_MouseEnter(object sender, MouseEventArgs e)
{
    btnAddFiles.Background = Brushes.Transparent;
}

private void btnAddFiles_MouseLeave(object sender, MouseEventArgs e)
{
    btnAddFiles.Background = Brushes.Lime;
}

2nd Edit: 第二次编辑:

for changing border color and thickness: 用于更改边框的颜色和厚度:

button1.BorderBrush = Brushes.Red;
Thickness t = new Thickness(5, 5, 5, 5);
button1.BorderThickness = t;

also change your margin, it is out form. 也改变您的保证金,这是表格。 try for example 尝试例如

Margin="50,50,0,0"

let me know if you get your answer. 让我知道你的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM