更改silverlight中的背景画刷属性后,为什么背景会自动改变?
代码如下:<UserControl.Resources><LinearGradientBrushx:Key="bgbrush"><GradientStopOffset="...
代码如下:
<UserControl.Resources>
<LinearGradientBrush x:Key="bgbrush">
<GradientStop Offset="0.00" Color="Yellow" />
<GradientStop Offset="0.50" Color="White" />
<GradientStop Offset="1.00" Color="Purple" />
</LinearGradientBrush>
</UserControl.Resources>
<Grid x:Name="grid1" MouseLeftButtonDown="grid1_MouseLeftButtonDown" Background="{StaticResource bgbrush }">
.................
</Grid>
</UserControl>
我设置了Grid的背景画刷,然后在鼠标左键下按的事件里更改画刷的属性:
private void grid1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
LinearGradientBrush brush = (LinearGradientBrush)this.Resources["bgbrush"];
Color color = brush.GradientStops[0].Color;
brush.GradientStops[0].Color = brush.GradientStops[2].Color;
brush.GradientStops[2].Color = color;
}
然后Grid的背景就自动变了,我不明白的是这里面有什么机制导致更改了画刷属性后,Grid会自动重绘呢?而不是像vc里面一样,要用程序刷新绘制区域才会看到新的效果。恳请高手解惑啊! 展开
<UserControl.Resources>
<LinearGradientBrush x:Key="bgbrush">
<GradientStop Offset="0.00" Color="Yellow" />
<GradientStop Offset="0.50" Color="White" />
<GradientStop Offset="1.00" Color="Purple" />
</LinearGradientBrush>
</UserControl.Resources>
<Grid x:Name="grid1" MouseLeftButtonDown="grid1_MouseLeftButtonDown" Background="{StaticResource bgbrush }">
.................
</Grid>
</UserControl>
我设置了Grid的背景画刷,然后在鼠标左键下按的事件里更改画刷的属性:
private void grid1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
LinearGradientBrush brush = (LinearGradientBrush)this.Resources["bgbrush"];
Color color = brush.GradientStops[0].Color;
brush.GradientStops[0].Color = brush.GradientStops[2].Color;
brush.GradientStops[2].Color = color;
}
然后Grid的背景就自动变了,我不明白的是这里面有什么机制导致更改了画刷属性后,Grid会自动重绘呢?而不是像vc里面一样,要用程序刷新绘制区域才会看到新的效果。恳请高手解惑啊! 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询