【问题标题】:Chnage Telerik WPF button color via code通过代码更改 Telerik WPF 按钮颜色
【发布时间】:2014-11-17 21:14:55
【问题描述】:

我学习WPF 并构建一个简单的应用程序。 这是我的按钮:

<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" />

这就是它的样子:

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

我已将按钮背景颜色更改为Transparent,因此您看到的背景颜色就是我的应用程序背景颜色。 我想做的就是当鼠标悬停在按钮上时,将背景颜色更改为Transparent。 当前这是鼠标悬停时的当前值:

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

所以我注册到MouseEnter event:

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

但我可以看到 btnAddFiles.Background 需要 BrushColor 有什么想法可以改变它吗?

【问题讨论】:

标签: c# css .net wpf telerik


【解决方案1】:

我看不到你的照片,但这是我们在 wpf 中改变颜色的方式:

btnAddFiles.Background = Brushes.Transparent;

您可以在鼠标进入和鼠标离开事件中使用您的代码。

第一次编辑

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

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

第二次编辑:

用于更改边框颜色和粗细:

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

也改变你的保证金,它是形式。例如尝试

Margin="50,50,0,0"

如果你得到答案,请告诉我。

【讨论】:

  • 有些东西很奇怪,当鼠标离开应用程序时,所有应用程序的颜色都变成了 Lime。顺便说一句,当鼠标悬停在控件上时,我可以使边框也透明吗?
  • 您应该更改按钮背景,但您似乎已将应用程序背景更改为石灰。创建一个新项目并测试我的代码,而无需对代码进行任何其他更改,它将正常工作。对于边界,我正在编辑我的答案。
  • 我所有表单更改的问题都解决了,我将您的代码放在我的按钮 MouseEnter 事件中,鼠标悬停在按钮上后,我仍然可以看到按钮边框(以某种颜色标记的按钮矩形) - 知道如何让它不可见吗?
  • 在边框粗细中将所有 5 更改为 0 则您没有任何边框。厚度 t = new Thickness(0, 0, 0, 0);
  • 我希望所有的矩形药房,厚度(0, 0, 0, 0)不是这种情况
猜你喜欢
  • 1970-01-01
  • 2016-09-11
  • 1970-01-01
  • 1970-01-01
  • 2017-12-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-18
相关资源
最近更新 更多