翼度科技»论坛 编程开发 .net 查看内容

13.画刷(Brush)

8

主题

8

帖子

24

积分

新手上路

Rank: 1

积分
24
在进行WPF界面设计时,我们需要在很多地方设置颜色属性,比如元素的背景色、前景色以及边框的颜色,还有形状的内部填充和笔画,这些颜色的设置在WPF中都以画刷(Brush)的形式实现。比如最常用的画刷就是SolidColorBrush,它表示一种纯色。
  1. public abstract class Brush : Animatable, IFormattable, IResource
  2. {
  3. <Window.Resources>
  4.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  5. </Window.Resources>
  6. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public static readonly DependencyProperty OpacityProperty;
  7. <Window.Resources>
  8.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  9. </Window.Resources>
  10. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public static readonly DependencyProperty TransformProperty;
  11. <Window.Resources>
  12.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  13. </Window.Resources>
  14. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public static readonly DependencyProperty RelativeTransformProperty;
  15. <Window.Resources>
  16.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  17. </Window.Resources>
  18. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> protected Brush();
  19. <Window.Resources>
  20.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  21. </Window.Resources>
  22. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public double Opacity { get; set; }
  23. <Window.Resources>
  24.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  25. </Window.Resources>
  26. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public Transform Transform { get; set; }
  27. <Window.Resources>
  28.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  29. </Window.Resources>
  30. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public Transform RelativeTransform { get; set; }
  31. <Window.Resources>
  32.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  33. </Window.Resources>
  34. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public Brush Clone();
  35. <Window.Resources>
  36.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  37. </Window.Resources>
  38. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public Brush CloneCurrentValue();
  39. <Window.Resources>
  40.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  41. </Window.Resources>
  42. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public override string ToString();
  43. <Window.Resources>
  44.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  45. </Window.Resources>
  46. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public string ToString(IFormatProvider provider);
  47. }
复制代码
Brush继承于Animatable基类和Freezable基类,说明它支持更改通知。如果改变了画刷,任何使用该画刷的控件的颜色都会自动重绘。
Opacity 属性表示它支持部分透明。
Brush一共有7个子类,下表中列出了它们的信息。
画刷名称功能说明
SolidColorBrush使用单一的连续颜色填充区域
LinearGradientBrush使用线性渐变绘制区域。
RadialGradientBrush使用径向渐变绘制区域。 焦点定义渐变的开始,而圆定义渐变的终点。
ImageBrush使用图像绘制区域。
VisualBrush使用一个视图绘制区域。
BitmapCacheBrush绘制带有缓存的内容的区域。
DrawingBrush使用包括形状、文本、视频、图像或其他绘制项等填充区域。
Brush基类和子类的继承关系

 
SolidColorBrush纯色画刷
SolidColorBrush继承于Brush抽象类,表示用某一种颜色填充区域。从定义上看,它拥有一个Color属性,表示具体的颜色值。
  1. public sealed class SolidColorBrush : Brush
  2. {
  3. <Window.Resources>
  4.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  5. </Window.Resources>
  6. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public static readonly DependencyProperty ColorProperty;
  7. <Window.Resources>
  8.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  9. </Window.Resources>
  10. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public SolidColorBrush();
  11. <Window.Resources>
  12.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  13. </Window.Resources>
  14. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public SolidColorBrush(Color color);
  15. <Window.Resources>
  16.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  17. </Window.Resources>
  18. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public Color Color { get; set; }
  19. <Window.Resources>
  20.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  21. </Window.Resources>
  22. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public static object DeserializeFrom(BinaryReader reader);
  23. <Window.Resources>
  24.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  25. </Window.Resources>
  26. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public SolidColorBrush Clone();
  27. <Window.Resources>
  28.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  29. </Window.Resources>
  30. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public SolidColorBrush CloneCurrentValue();
  31. }
复制代码
Color 在WPF中代表颜色值,被设计成一个结构体,主要是4个属性,即A、R、G、B,分别表示Alpha透明通道值,红色通道值、绿色通道值和蓝色通道值。它们的取值范围都是0-255
案列:
设置Grid的背景颜色
  1. <Grid>
  2. <Window.Resources>
  3.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  4. </Window.Resources>
  5. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Grid.Background>
  6. <Window.Resources>
  7.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  8. </Window.Resources>
  9. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  10.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  11. </Window.Resources>
  12. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  <<strong>SolidColorBrush</strong>>
  13. <Window.Resources>
  14.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  15. </Window.Resources>
  16. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  17.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  18. </Window.Resources>
  19. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  20.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  21. </Window.Resources>
  22. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <strong>  <SolidColorBrush.Color>
  23. <Window.Resources>
  24.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  25. </Window.Resources>
  26. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  27.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  28. </Window.Resources>
  29. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  30.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  31. </Window.Resources>
  32. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  33.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  34. </Window.Resources>
  35. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  36.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  37. </Window.Resources>
  38. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Color A="255" R="255" G="0" B="0"/>
  39. <Window.Resources>
  40.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  41. </Window.Resources>
  42. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  43.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  44. </Window.Resources>
  45. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  46.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  47. </Window.Resources>
  48. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  49.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  50. </Window.Resources>
  51. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/></SolidColorBrush.Color>
  52. <Window.Resources>
  53.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  54. </Window.Resources>
  55. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  56.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  57. </Window.Resources>
  58. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  </SolidColorBrush></strong>
  59. <Window.Resources>
  60.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  61. </Window.Resources>
  62. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> </Grid.Background>
  63. </Grid>
复制代码
C#代码的方式去设置背景颜色
  1. SolidColorBrush solidColorBrush = new SolidColorBrush();
  2. //使用系统自定义的颜色
  3. solidColorBrush.Color = Colors.Green;
  4. //或者从Color的FromRgb成员中得到颜色
  5. solidColorBrush.Color = Color.FromRgb(0, 0x80, 0);
  6. grid.Background = solidColorBrush;
复制代码
实例化成一个资源:
  1. <Window.Resources>
  2.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  3. </Window.Resources>
  4. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>
复制代码
 
LinearGradientBrush渐变画刷
LinearGradientBrush是一个比较有意思的画刷,它可以从一种颜色过渡到另一种颜色,使被填充的区域呈现渐变效果
  1. public sealed class LinearGradientBrush : GradientBrush{<Window.Resources>
  2.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  3. </Window.Resources>
  4. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public static readonly DependencyProperty StartPointProperty;<Window.Resources>
  5.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  6. </Window.Resources>
  7. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public static readonly DependencyProperty EndPointProperty;<Window.Resources>
  8.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  9. </Window.Resources>
  10. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  public LinearGradientBrush();<Window.Resources>
  11.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  12. </Window.Resources>
  13. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public LinearGradientBrush(GradientStopCollection gradientStopCollection);<Window.Resources>
  14.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  15. </Window.Resources>
  16. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public LinearGradientBrush(GradientStopCollection gradientStopCollection, double angle);<Window.Resources>
  17.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  18. </Window.Resources>
  19. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public LinearGradientBrush(Color startColor, Color endColor, double angle);<Window.Resources>
  20.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  21. </Window.Resources>
  22. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public LinearGradientBrush(GradientStopCollection gradientStopCollection, Point startPoint, Point endPoint);<Window.Resources>
  23.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  24. </Window.Resources>
  25. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public LinearGradientBrush(Color startColor, Color endColor, Point startPoint, Point endPoint);<Window.Resources>
  26.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  27. </Window.Resources>
  28. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  public Point StartPoint { get; set; }<Window.Resources>
  29.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  30. </Window.Resources>
  31. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public Point EndPoint { get; set; }<Window.Resources>
  32.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  33. </Window.Resources>
  34. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  public LinearGradientBrush Clone();<Window.Resources>
  35.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  36. </Window.Resources>
  37. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public LinearGradientBrush CloneCurrentValue();}
复制代码
从定义上看,它有StartPoint 和EndPoint 两个点,表示获取和设置线性渐变的二维起始坐标和结束坐标。而它因为继承于GradientBrush基类,所以它的颜色都保存在GradientStops集合属性中。GradientStops集合中的元素类型必须为GradientStop,表示渐变中转换点的位置和颜色。所以,GradientStop拥有Color属性和Offset属性,分别表示颜色值和偏移值。
案例:
一个Grid,希望从左上角设置一个绿色,右下角设置一个蓝色,中间是两种颜色的渐变效果
  1. <Grid>
  2. <Window.Resources>
  3.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  4. </Window.Resources>
  5. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Grid.Background>
  6. <Window.Resources>
  7.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  8. </Window.Resources>
  9. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  10.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  11. </Window.Resources>
  12. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  <<strong>SolidColorBrush</strong>>
  13. <Window.Resources>
  14.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  15. </Window.Resources>
  16. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  17.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  18. </Window.Resources>
  19. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  20.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  21. </Window.Resources>
  22. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <strong>  <SolidColorBrush.Color>
  23. <Window.Resources>
  24.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  25. </Window.Resources>
  26. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  27.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  28. </Window.Resources>
  29. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  30.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  31. </Window.Resources>
  32. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  33.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  34. </Window.Resources>
  35. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  36.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  37. </Window.Resources>
  38. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Color A="255" R="255" G="0" B="0"/>
  39. <Window.Resources>
  40.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  41. </Window.Resources>
  42. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  43.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  44. </Window.Resources>
  45. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  46.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  47. </Window.Resources>
  48. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  49.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  50. </Window.Resources>
  51. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/></SolidColorBrush.Color>
  52. <Window.Resources>
  53.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  54. </Window.Resources>
  55. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  56.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  57. </Window.Resources>
  58. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  </SolidColorBrush></strong>
  59. <Window.Resources>
  60.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  61. </Window.Resources>
  62. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> </Grid.Background>
  63. </Grid><Grid>
  64. <Window.Resources>
  65.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  66. </Window.Resources>
  67. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Grid.Background>
  68. <Window.Resources>
  69.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  70. </Window.Resources>
  71. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  72.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  73. </Window.Resources>
  74. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  <<strong>SolidColorBrush</strong>>
  75. <Window.Resources>
  76.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  77. </Window.Resources>
  78. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  79.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  80. </Window.Resources>
  81. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  82.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  83. </Window.Resources>
  84. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <strong>  <SolidColorBrush.Color>
  85. <Window.Resources>
  86.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  87. </Window.Resources>
  88. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  89.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  90. </Window.Resources>
  91. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  92.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  93. </Window.Resources>
  94. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  95.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  96. </Window.Resources>
  97. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  98.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  99. </Window.Resources>
  100. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Color A="255" R="255" G="0" B="0"/>
  101. <Window.Resources>
  102.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  103. </Window.Resources>
  104. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  105.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  106. </Window.Resources>
  107. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  108.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  109. </Window.Resources>
  110. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  111.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  112. </Window.Resources>
  113. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/></SolidColorBrush.Color>
  114. <Window.Resources>
  115.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  116. </Window.Resources>
  117. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  118.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  119. </Window.Resources>
  120. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  </SolidColorBrush></strong>
  121. <Window.Resources>
  122.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  123. </Window.Resources>
  124. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> </Grid.Background>
  125. </Grid><Window.Resources>
  126.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  127. </Window.Resources>
  128. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>
复制代码
LinearGradientBrush将整个Grid看成是一个0-1的矩形,所以StartPoint=(0,0)表示左上角,EndPoint=(1,1)表示右下角,这就控制了渐变的方向是从左上角到右下角的斜线。GradientStop 对象中的Offset表示在渐变方向上各颜色的占比或起点。假如我们将第一个GradientStop对象的Offset设置为0.5,那么此时的代码和效果如下所示:
  1. <Window.Resources>
  2.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  3. </Window.Resources>
  4. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  5.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  6. </Window.Resources>
  7. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  8.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  9. </Window.Resources>
  10. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  11.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  12. </Window.Resources>
  13. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  14.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  15. </Window.Resources>
  16. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  17.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  18. </Window.Resources>
  19. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  20.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  21. </Window.Resources>
  22. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  
复制代码

 
RadialGradientBrush径向渐变
RadialGradientBrush径向渐变像一个圆一样,从焦点中心位置开始向四周渐变,LinearGradientBrush线性渐变具有用于定义渐变矢量的起点和终点,而径向渐变具有一个圆和一个焦点,用于定义渐变行为。 圆定义渐变的终点。 换句话说,渐变停止点为 1.0 定义圆周的颜色。 焦点定义渐变的中心。 渐变停止点为 0.0 定义焦点处的颜色。
  1. public sealed class RadialGradientBrush : GradientBrush{<Window.Resources>
  2.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  3. </Window.Resources>
  4. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public static readonly DependencyProperty CenterProperty;<Window.Resources>
  5.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  6. </Window.Resources>
  7. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public static readonly DependencyProperty RadiusXProperty;<Window.Resources>
  8.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  9. </Window.Resources>
  10. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public static readonly DependencyProperty RadiusYProperty;<Window.Resources>
  11.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  12. </Window.Resources>
  13. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public static readonly DependencyProperty GradientOriginProperty;<Window.Resources>
  14.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  15. </Window.Resources>
  16. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  public RadialGradientBrush();<Window.Resources>
  17.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  18. </Window.Resources>
  19. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public RadialGradientBrush(GradientStopCollection gradientStopCollection);<Window.Resources>
  20.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  21. </Window.Resources>
  22. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public RadialGradientBrush(Color startColor, Color endColor);<Window.Resources>
  23.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  24. </Window.Resources>
  25. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  public Point Center { get; set; }<Window.Resources>
  26.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  27. </Window.Resources>
  28. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public double RadiusX { get; set; }<Window.Resources>
  29.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  30. </Window.Resources>
  31. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public double RadiusY { get; set; }<Window.Resources>
  32.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  33. </Window.Resources>
  34. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public Point GradientOrigin { get; set; }<Window.Resources>
  35.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  36. </Window.Resources>
  37. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  public RadialGradientBrush Clone();<Window.Resources>
  38.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  39. </Window.Resources>
  40. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public RadialGradientBrush CloneCurrentValue();}
复制代码
Center属性:获取或设置径向渐变的最外面圆的中心。
RadiusX属性:获取或设置径向渐变的最外面圆的水平半径。默认值为 0.5。
RadiusY属性:获取或设置径向渐变的最外面圆的垂直半径。默认值为 0.5。
GradientOrigin属性:获取或设置用于定义渐变开始的二维焦点的位置。默认值为 0.5。
以Ellipse控件为例,演示一下RadialGradientBrush 的用法:
  1. <Grid>
  2. <Window.Resources>
  3.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  4. </Window.Resources>
  5. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Grid.Background>
  6. <Window.Resources>
  7.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  8. </Window.Resources>
  9. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  10.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  11. </Window.Resources>
  12. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  <<strong>SolidColorBrush</strong>>
  13. <Window.Resources>
  14.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  15. </Window.Resources>
  16. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  17.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  18. </Window.Resources>
  19. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  20.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  21. </Window.Resources>
  22. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <strong>  <SolidColorBrush.Color>
  23. <Window.Resources>
  24.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  25. </Window.Resources>
  26. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  27.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  28. </Window.Resources>
  29. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  30.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  31. </Window.Resources>
  32. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  33.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  34. </Window.Resources>
  35. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  36.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  37. </Window.Resources>
  38. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Color A="255" R="255" G="0" B="0"/>
  39. <Window.Resources>
  40.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  41. </Window.Resources>
  42. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  43.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  44. </Window.Resources>
  45. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  46.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  47. </Window.Resources>
  48. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  49.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  50. </Window.Resources>
  51. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/></SolidColorBrush.Color>
  52. <Window.Resources>
  53.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  54. </Window.Resources>
  55. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  56.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  57. </Window.Resources>
  58. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  </SolidColorBrush></strong>
  59. <Window.Resources>
  60.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  61. </Window.Resources>
  62. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> </Grid.Background>
  63. </Grid><Grid>
  64. <Window.Resources>
  65.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  66. </Window.Resources>
  67. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Grid.Background>
  68. <Window.Resources>
  69.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  70. </Window.Resources>
  71. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  72.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  73. </Window.Resources>
  74. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  <<strong>SolidColorBrush</strong>>
  75. <Window.Resources>
  76.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  77. </Window.Resources>
  78. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  79.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  80. </Window.Resources>
  81. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  82.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  83. </Window.Resources>
  84. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <strong>  <SolidColorBrush.Color>
  85. <Window.Resources>
  86.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  87. </Window.Resources>
  88. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  89.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  90. </Window.Resources>
  91. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  92.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  93. </Window.Resources>
  94. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  95.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  96. </Window.Resources>
  97. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  98.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  99. </Window.Resources>
  100. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Color A="255" R="255" G="0" B="0"/>
  101. <Window.Resources>
  102.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  103. </Window.Resources>
  104. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  105.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  106. </Window.Resources>
  107. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  108.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  109. </Window.Resources>
  110. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  111.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  112. </Window.Resources>
  113. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/></SolidColorBrush.Color>
  114. <Window.Resources>
  115.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  116. </Window.Resources>
  117. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  118.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  119. </Window.Resources>
  120. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  </SolidColorBrush></strong>
  121. <Window.Resources>
  122.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  123. </Window.Resources>
  124. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> </Grid.Background>
  125. </Grid><Grid>
  126. <Window.Resources>
  127.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  128. </Window.Resources>
  129. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Grid.Background>
  130. <Window.Resources>
  131.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  132. </Window.Resources>
  133. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  134.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  135. </Window.Resources>
  136. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  <<strong>SolidColorBrush</strong>>
  137. <Window.Resources>
  138.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  139. </Window.Resources>
  140. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  141.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  142. </Window.Resources>
  143. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  144.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  145. </Window.Resources>
  146. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <strong>  <SolidColorBrush.Color>
  147. <Window.Resources>
  148.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  149. </Window.Resources>
  150. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  151.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  152. </Window.Resources>
  153. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  154.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  155. </Window.Resources>
  156. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  157.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  158. </Window.Resources>
  159. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  160.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  161. </Window.Resources>
  162. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Color A="255" R="255" G="0" B="0"/>
  163. <Window.Resources>
  164.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  165. </Window.Resources>
  166. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  167.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  168. </Window.Resources>
  169. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  170.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  171. </Window.Resources>
  172. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  173.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  174. </Window.Resources>
  175. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/></SolidColorBrush.Color>
  176. <Window.Resources>
  177.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  178. </Window.Resources>
  179. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  180.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  181. </Window.Resources>
  182. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  </SolidColorBrush></strong>
  183. <Window.Resources>
  184.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  185. </Window.Resources>
  186. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> </Grid.Background>
  187. </Grid><Grid>
  188. <Window.Resources>
  189.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  190. </Window.Resources>
  191. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Grid.Background>
  192. <Window.Resources>
  193.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  194. </Window.Resources>
  195. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  196.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  197. </Window.Resources>
  198. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  <<strong>SolidColorBrush</strong>>
  199. <Window.Resources>
  200.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  201. </Window.Resources>
  202. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  203.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  204. </Window.Resources>
  205. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  206.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  207. </Window.Resources>
  208. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <strong>  <SolidColorBrush.Color>
  209. <Window.Resources>
  210.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  211. </Window.Resources>
  212. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  213.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  214. </Window.Resources>
  215. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  216.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  217. </Window.Resources>
  218. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  219.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  220. </Window.Resources>
  221. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  222.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  223. </Window.Resources>
  224. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Color A="255" R="255" G="0" B="0"/>
  225. <Window.Resources>
  226.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  227. </Window.Resources>
  228. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  229.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  230. </Window.Resources>
  231. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  232.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  233. </Window.Resources>
  234. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  235.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  236. </Window.Resources>
  237. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/></SolidColorBrush.Color>
  238. <Window.Resources>
  239.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  240. </Window.Resources>
  241. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  242.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  243. </Window.Resources>
  244. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  </SolidColorBrush></strong>
  245. <Window.Resources>
  246.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  247. </Window.Resources>
  248. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> </Grid.Background>
  249. </Grid><Grid>
  250. <Window.Resources>
  251.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  252. </Window.Resources>
  253. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Grid.Background>
  254. <Window.Resources>
  255.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  256. </Window.Resources>
  257. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  258.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  259. </Window.Resources>
  260. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  <<strong>SolidColorBrush</strong>>
  261. <Window.Resources>
  262.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  263. </Window.Resources>
  264. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  265.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  266. </Window.Resources>
  267. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  268.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  269. </Window.Resources>
  270. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <strong>  <SolidColorBrush.Color>
  271. <Window.Resources>
  272.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  273. </Window.Resources>
  274. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  275.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  276. </Window.Resources>
  277. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  278.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  279. </Window.Resources>
  280. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  281.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  282. </Window.Resources>
  283. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  284.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  285. </Window.Resources>
  286. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Color A="255" R="255" G="0" B="0"/>
  287. <Window.Resources>
  288.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  289. </Window.Resources>
  290. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  291.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  292. </Window.Resources>
  293. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  294.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  295. </Window.Resources>
  296. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  297.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  298. </Window.Resources>
  299. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/></SolidColorBrush.Color>
  300. <Window.Resources>
  301.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  302. </Window.Resources>
  303. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  304.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  305. </Window.Resources>
  306. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  </SolidColorBrush></strong>
  307. <Window.Resources>
  308.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  309. </Window.Resources>
  310. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> </Grid.Background>
  311. </Grid><Window.Resources>
  312.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  313. </Window.Resources>
  314. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  315.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  316. </Window.Resources>
  317. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  318.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  319. </Window.Resources>
  320. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>
复制代码

在上面的代码中,处于圆中心的白色渐变点由GradientOrigin属性控制,如果将值改成:GradientOrigin="0.25,0.25",那么它会呈现下面的样子。

根据这个特性,我们可以实现一个有趣的示例。那就是当鼠标移动到椭圆内,这个径向渐变的起点坐标跟随鼠标位置变化而变化。
  1. <Grid>
  2. <Window.Resources>
  3.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  4. </Window.Resources>
  5. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Grid.Background>
  6. <Window.Resources>
  7.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  8. </Window.Resources>
  9. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  10.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  11. </Window.Resources>
  12. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  <<strong>SolidColorBrush</strong>>
  13. <Window.Resources>
  14.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  15. </Window.Resources>
  16. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  17.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  18. </Window.Resources>
  19. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  20.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  21. </Window.Resources>
  22. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <strong>  <SolidColorBrush.Color>
  23. <Window.Resources>
  24.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  25. </Window.Resources>
  26. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  27.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  28. </Window.Resources>
  29. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  30.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  31. </Window.Resources>
  32. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  33.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  34. </Window.Resources>
  35. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  36.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  37. </Window.Resources>
  38. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Color A="255" R="255" G="0" B="0"/>
  39. <Window.Resources>
  40.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  41. </Window.Resources>
  42. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  43.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  44. </Window.Resources>
  45. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  46.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  47. </Window.Resources>
  48. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  49.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  50. </Window.Resources>
  51. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/></SolidColorBrush.Color>
  52. <Window.Resources>
  53.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  54. </Window.Resources>
  55. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  56.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  57. </Window.Resources>
  58. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  </SolidColorBrush></strong>
  59. <Window.Resources>
  60.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  61. </Window.Resources>
  62. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> </Grid.Background>
  63. </Grid><Grid>
  64. <Window.Resources>
  65.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  66. </Window.Resources>
  67. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Grid.Background>
  68. <Window.Resources>
  69.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  70. </Window.Resources>
  71. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  72.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  73. </Window.Resources>
  74. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  <<strong>SolidColorBrush</strong>>
  75. <Window.Resources>
  76.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  77. </Window.Resources>
  78. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  79.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  80. </Window.Resources>
  81. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  82.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  83. </Window.Resources>
  84. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <strong>  <SolidColorBrush.Color>
  85. <Window.Resources>
  86.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  87. </Window.Resources>
  88. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  89.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  90. </Window.Resources>
  91. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  92.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  93. </Window.Resources>
  94. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  95.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  96. </Window.Resources>
  97. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  98.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  99. </Window.Resources>
  100. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Color A="255" R="255" G="0" B="0"/>
  101. <Window.Resources>
  102.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  103. </Window.Resources>
  104. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  105.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  106. </Window.Resources>
  107. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  108.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  109. </Window.Resources>
  110. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  111.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  112. </Window.Resources>
  113. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/></SolidColorBrush.Color>
  114. <Window.Resources>
  115.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  116. </Window.Resources>
  117. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  118.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  119. </Window.Resources>
  120. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  </SolidColorBrush></strong>
  121. <Window.Resources>
  122.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  123. </Window.Resources>
  124. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> </Grid.Background>
  125. </Grid><Grid>
  126. <Window.Resources>
  127.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  128. </Window.Resources>
  129. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Grid.Background>
  130. <Window.Resources>
  131.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  132. </Window.Resources>
  133. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  134.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  135. </Window.Resources>
  136. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  <<strong>SolidColorBrush</strong>>
  137. <Window.Resources>
  138.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  139. </Window.Resources>
  140. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  141.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  142. </Window.Resources>
  143. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  144.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  145. </Window.Resources>
  146. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <strong>  <SolidColorBrush.Color>
  147. <Window.Resources>
  148.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  149. </Window.Resources>
  150. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  151.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  152. </Window.Resources>
  153. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  154.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  155. </Window.Resources>
  156. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  157.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  158. </Window.Resources>
  159. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  160.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  161. </Window.Resources>
  162. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Color A="255" R="255" G="0" B="0"/>
  163. <Window.Resources>
  164.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  165. </Window.Resources>
  166. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  167.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  168. </Window.Resources>
  169. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  170.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  171. </Window.Resources>
  172. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  173.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  174. </Window.Resources>
  175. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/></SolidColorBrush.Color>
  176. <Window.Resources>
  177.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  178. </Window.Resources>
  179. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  180.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  181. </Window.Resources>
  182. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  </SolidColorBrush></strong>
  183. <Window.Resources>
  184.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  185. </Window.Resources>
  186. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> </Grid.Background>
  187. </Grid><Grid>
  188. <Window.Resources>
  189.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  190. </Window.Resources>
  191. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Grid.Background>
  192. <Window.Resources>
  193.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  194. </Window.Resources>
  195. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  196.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  197. </Window.Resources>
  198. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  <<strong>SolidColorBrush</strong>>
  199. <Window.Resources>
  200.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  201. </Window.Resources>
  202. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  203.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  204. </Window.Resources>
  205. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  206.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  207. </Window.Resources>
  208. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <strong>  <SolidColorBrush.Color>
  209. <Window.Resources>
  210.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  211. </Window.Resources>
  212. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  213.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  214. </Window.Resources>
  215. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  216.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  217. </Window.Resources>
  218. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  219.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  220. </Window.Resources>
  221. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  222.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  223. </Window.Resources>
  224. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Color A="255" R="255" G="0" B="0"/>
  225. <Window.Resources>
  226.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  227. </Window.Resources>
  228. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  229.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  230. </Window.Resources>
  231. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  232.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  233. </Window.Resources>
  234. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  235.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  236. </Window.Resources>
  237. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/></SolidColorBrush.Color>
  238. <Window.Resources>
  239.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  240. </Window.Resources>
  241. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  242.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  243. </Window.Resources>
  244. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  </SolidColorBrush></strong>
  245. <Window.Resources>
  246.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  247. </Window.Resources>
  248. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> </Grid.Background>
  249. </Grid><Grid>
  250. <Window.Resources>
  251.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  252. </Window.Resources>
  253. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Grid.Background>
  254. <Window.Resources>
  255.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  256. </Window.Resources>
  257. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  258.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  259. </Window.Resources>
  260. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  <<strong>SolidColorBrush</strong>>
  261. <Window.Resources>
  262.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  263. </Window.Resources>
  264. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  265.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  266. </Window.Resources>
  267. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  268.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  269. </Window.Resources>
  270. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <strong>  <SolidColorBrush.Color>
  271. <Window.Resources>
  272.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  273. </Window.Resources>
  274. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  275.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  276. </Window.Resources>
  277. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  278.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  279. </Window.Resources>
  280. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  281.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  282. </Window.Resources>
  283. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  284.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  285. </Window.Resources>
  286. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Color A="255" R="255" G="0" B="0"/>
  287. <Window.Resources>
  288.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  289. </Window.Resources>
  290. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  291.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  292. </Window.Resources>
  293. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  294.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  295. </Window.Resources>
  296. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  297.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  298. </Window.Resources>
  299. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/></SolidColorBrush.Color>
  300. <Window.Resources>
  301.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  302. </Window.Resources>
  303. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  304.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  305. </Window.Resources>
  306. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  </SolidColorBrush></strong>
  307. <Window.Resources>
  308.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  309. </Window.Resources>
  310. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> </Grid.Background>
  311. </Grid><Grid>
  312. <Window.Resources>
  313.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  314. </Window.Resources>
  315. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Grid.Background>
  316. <Window.Resources>
  317.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  318. </Window.Resources>
  319. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  320.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  321. </Window.Resources>
  322. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  <<strong>SolidColorBrush</strong>>
  323. <Window.Resources>
  324.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  325. </Window.Resources>
  326. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  327.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  328. </Window.Resources>
  329. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  330.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  331. </Window.Resources>
  332. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <strong>  <SolidColorBrush.Color>
  333. <Window.Resources>
  334.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  335. </Window.Resources>
  336. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  337.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  338. </Window.Resources>
  339. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  340.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  341. </Window.Resources>
  342. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  343.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  344. </Window.Resources>
  345. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  346.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  347. </Window.Resources>
  348. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Color A="255" R="255" G="0" B="0"/>
  349. <Window.Resources>
  350.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  351. </Window.Resources>
  352. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  353.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  354. </Window.Resources>
  355. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  356.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  357. </Window.Resources>
  358. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  359.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  360. </Window.Resources>
  361. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/></SolidColorBrush.Color>
  362. <Window.Resources>
  363.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  364. </Window.Resources>
  365. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  366.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  367. </Window.Resources>
  368. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  </SolidColorBrush></strong>
  369. <Window.Resources>
  370.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  371. </Window.Resources>
  372. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> </Grid.Background>
  373. </Grid><Grid>
  374. <Window.Resources>
  375.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  376. </Window.Resources>
  377. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Grid.Background>
  378. <Window.Resources>
  379.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  380. </Window.Resources>
  381. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  382.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  383. </Window.Resources>
  384. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  <<strong>SolidColorBrush</strong>>
  385. <Window.Resources>
  386.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  387. </Window.Resources>
  388. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  389.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  390. </Window.Resources>
  391. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  392.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  393. </Window.Resources>
  394. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <strong>  <SolidColorBrush.Color>
  395. <Window.Resources>
  396.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  397. </Window.Resources>
  398. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  399.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  400. </Window.Resources>
  401. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  402.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  403. </Window.Resources>
  404. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  405.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  406. </Window.Resources>
  407. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  408.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  409. </Window.Resources>
  410. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Color A="255" R="255" G="0" B="0"/>
  411. <Window.Resources>
  412.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  413. </Window.Resources>
  414. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  415.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  416. </Window.Resources>
  417. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  418.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  419. </Window.Resources>
  420. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  421.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  422. </Window.Resources>
  423. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/></SolidColorBrush.Color>
  424. <Window.Resources>
  425.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  426. </Window.Resources>
  427. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  428.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  429. </Window.Resources>
  430. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  </SolidColorBrush></strong>
  431. <Window.Resources>
  432.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  433. </Window.Resources>
  434. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> </Grid.Background>
  435. </Grid><Window.Resources>
  436.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  437. </Window.Resources>
  438. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  439.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  440. </Window.Resources>
  441. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  442.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  443. </Window.Resources>
  444. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  445.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  446. </Window.Resources>
  447. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  448.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  449. </Window.Resources>
  450. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  451.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  452. </Window.Resources>
  453. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>
复制代码
  1. private void ellipse_MouseMove(object sender, MouseEventArgs e){<Window.Resources>
  2.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  3. </Window.Resources>
  4. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> Ellipse ellipse = e.Source as Ellipse;<Window.Resources>
  5.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  6. </Window.Resources>
  7. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> Point point = e.GetPosition(ellipse);<Window.Resources>
  8.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  9. </Window.Resources>
  10. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> double width = ellipse.Width;<Window.Resources>
  11.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  12. </Window.Resources>
  13. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> double height = ellipse.Height;<Window.Resources>
  14.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  15. </Window.Resources>
  16. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> RadialGradientBrush brush = ellipse.Fill as RadialGradientBrush;<Window.Resources>
  17.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  18. </Window.Resources>
  19. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> double x = point.X / width;<Window.Resources>
  20.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  21. </Window.Resources>
  22. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> double y = point.Y / height;<Window.Resources>
  23.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  24. </Window.Resources>
  25. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> brush.GradientOrigin = new Point(x, y);}
复制代码
 
ImageBrush图像画刷
ImageBrush表示使用图像绘制区域。它继承于TileBrush抽象基类,另外,DrawingBrush和VisualBrush也继承于TileBrush抽象基类。
TileBrush 有三种不同类型,其中每一种都使用不同类型的内容进行绘制。下面列出它3个子类的情况。

  • 若使用ImageBrush子类,则画刷的填充内容是图像;
  • 若使用DrawingBrush子类,则画刷的填充内容是绘图;
  • 若使用VisualBrush子类,则画刷的填充内容是视觉对象(视觉树或控件);
  1. public abstract class TileBrush : Brush{<Window.Resources>
  2.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  3. </Window.Resources>
  4. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public static readonly DependencyProperty ViewportUnitsProperty;<Window.Resources>
  5.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  6. </Window.Resources>
  7. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public static readonly DependencyProperty ViewboxUnitsProperty;<Window.Resources>
  8.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  9. </Window.Resources>
  10. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public static readonly DependencyProperty ViewportProperty;<Window.Resources>
  11.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  12. </Window.Resources>
  13. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public static readonly DependencyProperty ViewboxProperty;<Window.Resources>
  14.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  15. </Window.Resources>
  16. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public static readonly DependencyProperty StretchProperty;<Window.Resources>
  17.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  18. </Window.Resources>
  19. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public static readonly DependencyProperty TileModeProperty;<Window.Resources>
  20.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  21. </Window.Resources>
  22. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public static readonly DependencyProperty AlignmentXProperty;<Window.Resources>
  23.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  24. </Window.Resources>
  25. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public static readonly DependencyProperty AlignmentYProperty;<Window.Resources>
  26.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  27. </Window.Resources>
  28. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  protected TileBrush();<Window.Resources>
  29.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  30. </Window.Resources>
  31. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  public TileMode TileMode { get; set; }<Window.Resources>
  32.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  33. </Window.Resources>
  34. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public Stretch Stretch { get; set; }<Window.Resources>
  35.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  36. </Window.Resources>
  37. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public Rect Viewbox { get; set; }<Window.Resources>
  38.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  39. </Window.Resources>
  40. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public Rect Viewport { get; set; }<Window.Resources>
  41.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  42. </Window.Resources>
  43. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public AlignmentY AlignmentY { get; set; }<Window.Resources>
  44.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  45. </Window.Resources>
  46. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public BrushMappingMode ViewportUnits { get; set; }<Window.Resources>
  47.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  48. </Window.Resources>
  49. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public AlignmentX AlignmentX { get; set; }<Window.Resources>
  50.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  51. </Window.Resources>
  52. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public BrushMappingMode ViewboxUnits { get; set; }<Window.Resources>
  53.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  54. </Window.Resources>
  55. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  public TileBrush Clone();<Window.Resources>
  56.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  57. </Window.Resources>
  58. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public TileBrush CloneCurrentValue();<Window.Resources>
  59.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  60. </Window.Resources>
  61. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> protected abstract void GetContentBounds(out Rect contentBounds);}
复制代码
TileMode 属性:获取或设置基本图块如何填充区域。枚举型,它一共有5个值,Tile表示在可用区域复制图像;FlipX表示复制图像但垂直翻转每个第二列;FlipY表示复制图像但水平翻转每个第二行;FlipXY表示复制图像,但是垂直翻转每个第二列,半水平翻转每个第二行。
Stretch 属性:获取或设置内容如何拉伸。
Viewbox 属性:获取或设置图块中内容的位置和尺寸。
Viewport 属性:获取或设置基本图块的位置和尺寸。它的类型是Rect,也就是用它来指定截取原图片的某个区域进行填充,这个区域的设置可以用绝对值和相对值两种方式设置,对应属性是ViewboxUnits,它有两个值,Absolute表示取绝对坐标,RelativeToBoundingBox表示取相对坐标。
AlignmentY属性:获取或设置基本图块的垂直对齐方式。
AlignmentX属性:获取或设置基本图块的垂直水平方式。
ViewboxUnits属性:获取或设置Viewbox的值是相对内容的边界框而言,还是绝对值。
ViewportUnits属性:获取或设置Viewport的值 是否是相对于输出区域的大小。
ImageBrush的定义:
  1. public sealed class ImageBrush : TileBrush{<Window.Resources>
  2.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  3. </Window.Resources>
  4. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public static readonly DependencyProperty ImageSourceProperty;<Window.Resources>
  5.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  6. </Window.Resources>
  7. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  public ImageBrush();<Window.Resources>
  8.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  9. </Window.Resources>
  10. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public ImageBrush(ImageSource image);<Window.Resources>
  11.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  12. </Window.Resources>
  13. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  public ImageSource ImageSource { get; set; }<Window.Resources>
  14.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  15. </Window.Resources>
  16. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  public ImageBrush Clone();<Window.Resources>
  17.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  18. </Window.Resources>
  19. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> public ImageBrush CloneCurrentValue();<Window.Resources>
  20.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  21. </Window.Resources>
  22. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> protected override Freezable CreateInstanceCore();<Window.Resources>
  23.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  24. </Window.Resources>
  25. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> protected override void GetContentBounds(out Rect contentBounds);}
复制代码
ImageBrush 画刷只需要设置它的ImageSource 属性,其它的属性都是从它的基类TileBrush继承而来
案例:
  1. <Grid>
  2. <Window.Resources>
  3.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  4. </Window.Resources>
  5. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Grid.Background>
  6. <Window.Resources>
  7.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  8. </Window.Resources>
  9. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  10.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  11. </Window.Resources>
  12. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  <<strong>SolidColorBrush</strong>>
  13. <Window.Resources>
  14.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  15. </Window.Resources>
  16. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  17.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  18. </Window.Resources>
  19. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  20.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  21. </Window.Resources>
  22. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <strong>  <SolidColorBrush.Color>
  23. <Window.Resources>
  24.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  25. </Window.Resources>
  26. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  27.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  28. </Window.Resources>
  29. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  30.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  31. </Window.Resources>
  32. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  33.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  34. </Window.Resources>
  35. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  36.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  37. </Window.Resources>
  38. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Color A="255" R="255" G="0" B="0"/>
  39. <Window.Resources>
  40.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  41. </Window.Resources>
  42. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  43.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  44. </Window.Resources>
  45. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  46.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  47. </Window.Resources>
  48. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  49.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  50. </Window.Resources>
  51. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/></SolidColorBrush.Color>
  52. <Window.Resources>
  53.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  54. </Window.Resources>
  55. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  56.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  57. </Window.Resources>
  58. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  </SolidColorBrush></strong>
  59. <Window.Resources>
  60.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  61. </Window.Resources>
  62. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> </Grid.Background>
  63. </Grid><Grid>
  64. <Window.Resources>
  65.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  66. </Window.Resources>
  67. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Grid.Background>
  68. <Window.Resources>
  69.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  70. </Window.Resources>
  71. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  72.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  73. </Window.Resources>
  74. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  <<strong>SolidColorBrush</strong>>
  75. <Window.Resources>
  76.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  77. </Window.Resources>
  78. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  79.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  80. </Window.Resources>
  81. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  82.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  83. </Window.Resources>
  84. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <strong>  <SolidColorBrush.Color>
  85. <Window.Resources>
  86.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  87. </Window.Resources>
  88. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  89.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  90. </Window.Resources>
  91. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  92.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  93. </Window.Resources>
  94. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  95.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  96. </Window.Resources>
  97. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  98.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  99. </Window.Resources>
  100. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Color A="255" R="255" G="0" B="0"/>
  101. <Window.Resources>
  102.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  103. </Window.Resources>
  104. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  105.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  106. </Window.Resources>
  107. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  108.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  109. </Window.Resources>
  110. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  111.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  112. </Window.Resources>
  113. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/></SolidColorBrush.Color>
  114. <Window.Resources>
  115.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  116. </Window.Resources>
  117. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  118.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  119. </Window.Resources>
  120. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  </SolidColorBrush></strong>
  121. <Window.Resources>
  122.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  123. </Window.Resources>
  124. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> </Grid.Background>
  125. </Grid><Grid>
  126. <Window.Resources>
  127.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  128. </Window.Resources>
  129. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Grid.Background>
  130. <Window.Resources>
  131.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  132. </Window.Resources>
  133. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  134.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  135. </Window.Resources>
  136. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  <<strong>SolidColorBrush</strong>>
  137. <Window.Resources>
  138.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  139. </Window.Resources>
  140. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  141.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  142. </Window.Resources>
  143. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  144.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  145. </Window.Resources>
  146. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <strong>  <SolidColorBrush.Color>
  147. <Window.Resources>
  148.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  149. </Window.Resources>
  150. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  151.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  152. </Window.Resources>
  153. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  154.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  155. </Window.Resources>
  156. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  157.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  158. </Window.Resources>
  159. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  160.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  161. </Window.Resources>
  162. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> <Color A="255" R="255" G="0" B="0"/>
  163. <Window.Resources>
  164.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  165. </Window.Resources>
  166. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  167.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  168. </Window.Resources>
  169. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  170.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  171. </Window.Resources>
  172. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  173.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  174. </Window.Resources>
  175. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/></SolidColorBrush.Color>
  176. <Window.Resources>
  177.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  178. </Window.Resources>
  179. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  180.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  181. </Window.Resources>
  182. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>  </SolidColorBrush></strong>
  183. <Window.Resources>
  184.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  185. </Window.Resources>
  186. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> </Grid.Background>
  187. </Grid><Window.Resources>
  188.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  189. </Window.Resources>
  190. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  191.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  192. </Window.Resources>
  193. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  194.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  195. </Window.Resources>
  196. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  197.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  198. </Window.Resources>
  199. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  200.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  201. </Window.Resources>
  202. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/><Window.Resources>
  203.    <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
  204. </Window.Resources>
  205. <Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/>
复制代码
在上面的代码中,我们给Grid控件设置了一个ImageBrush 图像画刷,并设置Stretch为UniformToFill,即自适应填充,同时设置了Viewport。那么它运行之后呈现的效果如下:

此时的Grid的背景其实就是一张图片。我们给Window对象的MouseWheel事件订阅了一个回调函数,并在其实改变了Viewport的宽度和高度。滚动鼠标的滚轮,此时Grid的背景图像的填充将会呈现如下的样子:
[code]private void Window_MouseWheel(object sender, MouseWheelEventArgs e){<Window.Resources>
   <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
</Window.Resources>
<Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> double offset = e.Delta / 3600.0;<Window.Resources>
   <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
</Window.Resources>
<Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> ImageBrush imageBrush = grid.Background as ImageBrush;<Window.Resources>
   <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
</Window.Resources>
<Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> Rect rect = imageBrush.Viewport;<Window.Resources>
   <strong> <SolidColorBrush x:Key="BackgroundBrush" Color="#123456"/></strong>
</Window.Resources>
<Grid x:Name="grid" Background="{StaticResource <strong>BackgroundBrush</strong>}"/> if (rect.Width + offset

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

举报 回复 使用道具