我正在创建一个 WPF 'Button' 控件并使其成为我的 ElementHost 控件的子控件。
按钮的背景设置为红色。
当我运行我的项目时,按钮会改变颜色,它似乎每隔几秒钟就会循环一次,从红色变为浅蓝色然后再返回......直到表单失去焦点。
如果我将鼠标悬停在按钮上,它会变成蓝色,然后当我离开按钮时,它会再次开始这种颜色循环......我的代码就像......
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
System.Windows.Controls.Button but = new System.Windows.Controls.Button();
but.Background = System.Windows.Media.Brushes.Red;
elementHost1.Child = but;
}
}
这是正常的吗?我可以关掉它吗?