WPF学习笔记(五)Brush

   画刷是WPF中最常用的对象之一,主要在System.Windows.Media命名空间内,Brush的继承树为

        object---dispatchobject----dependencyObject---Freezable---Animatable---Brush---GradientBrush等

      其中SolidColorBrush对象是最简单的画刷,是单一颜色的,而GradientBrush是渐变画刷,包括两个子类LinearGradientBrush

   与RadialGradientBrush.       也有Brushes对象可以用来直接使用。 例如:

                      PropertyInfo[] pro=typeof(Brushes).GetProperties();

                      Background=(Brush)pro[index].GetValue(null,null);

            注:须在命名空间中加入System.Reflection。

  渐变画刷大致包括指定几个Point对象,并指定该点的颜色。。例 :LinearGradientBrush linear=new LinearGradientBrush(Colors.Red,Colors.Blue,new Point(0.5,0.5),new Point(0.8,0.8)); 红色到蓝色的渐变。

   GradientBrush有以下几个属性值得注意:

                StartPoint与EndPoint .

                MappingMode决定是否使用相对坐标 (即(1,1)代表右下角),它是BrushMappingMode的枚举;

                SpreadMethod 属性决定超出部分的颜色。 是GradientSpreadMethod的枚举,Pad,Reflect,Repeat 。

                GradientStops是GradientStopCollection类型,而GradientStop具有Color与Offset属性  ,

            RadialGradientBrush 椭圆形渐变,其中Center  RadiusX   RadiusY  决定椭圆,GradientOrigin是渐变开始的点,

此外还有TileBrush---DrawingBrush.  ImageBrush  . VisualBrush  

      ImageBrush :  顾名思义就是图像画刷。主要属性是ImageSource

      等

              

首先继承树如下:

Object---DispatcherObject---DependencyObject---Visual---UIElement---FrameworkElement---Control--ContentControl

窗体表现的重点就是内容Content;Content几乎可以是任何对象。

WPF中没有专用的Font类,与字体相关的主要是FontFamily , FontStyle ,FontWeight FontSize

常用的字体有Courier New, Times New Roman , Arial Palatino Linotype ,Verdana, Comic Sans MS, Century Gothic

例:FontFamily=new FontFamily("Times New Roman Bold Italic");

shape---ellipse,polyline,line,path,rectangle

TextBlock对象;

TextBlock txb=new TextBlock();

txb.Inlines.Add("hello");

txb.Inlines.Add(new Italic(new Run("hello")));

txb.Inlines.Add(new Bold(new Run("hello")));

       

 

 

 

 

 

你可能感兴趣的:(学习笔记)