我正在尝试使用LinearGradientBrush绘制我的WPF窗口的背景,但是我的代码不能工作。以下是代码
LinearGradientBrush gradientBrush = new LinearGradientBrush( Color.FromArgb(0, 209, 227, 250), Color.FromArgb(0, 170, 199, 238), new Point(0.5, 0), new Point(0.5, 1));
Background = gradientBrush;奇怪的是,我的窗户仍然是白色的。是否可以使用后台代码更改窗口的背景色?
发布于 2012-11-25 06:08:42
您也在设置alpha设置。使用下面的代码,因为你想要颜色:
LinearGradientBrush gradientBrush = new LinearGradientBrush( Color.FromRgb( 209, 227, 250), Color.FromRgb(170, 199, 238), new Point(0.5, 0), new Point(0.5, 1));
Background = gradientBrush;发布于 2018-04-18 15:35:28
<Border.Background>
<LinearGradientBrush StartPoint="0 0" EndPoint="0 1">
<LinearGradientBrush.GradientStops>
<GradientStop Offset="0.1" Color="{Binding Path=YourBindColor1}" />
<GradientStop Offset="1" Color="{Binding Path=YourBindColor2}" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Border.Background>//使用绑定颜色
发布于 2011-09-12 04:48:56
将Window.Background设置为不同的画笔应该可以。
确保您的背景属性未通过{Binding}指令数据绑定到属性。
此外,尝试将其设置为更简单的画笔-例如
Background = new SolidColorBrush(Colors.Black);
https://stackoverflow.com/questions/7381097
复制相似问题