反射提供了封装程序集、模块和类型的对象(Type 类型)。可以使用反射动态创建类型的实例,将类型绑定到现有对象,或从现有对象获取类型并调用其方法或访问其字段和属性。如果代码中使用了属性,可以利用反射对它们进行访问。
有了反射,即可对每一个类型了如指掌。如果获得了构造函数的信息,即可直接创建对象,即使这个对象的类型在编译时还不知道。 然而要适量应用反射,它对性能有一定影响,反射的性能损失主要来源于比较类型、遍历成员、调用成员三种情形,其中比较类型耗时最小,调用成员耗时最多,所以尽量减少采用成员动态调用等反射方式可以提高应用程序性能。除此之外,采取后期绑定、避免将反射方法放到循环内产生放大效应等办法均可提升反射性能。
我们可以把属性比较繁琐的控件的属性组织为xml形式,解析xml利用反射为控件付属性。把xml保存到数据库或文件,这样我们就可以不修改代码改变控件。下边以mschart为例。
属性xml:
View Code
<?xml version="1.0" encoding="gb2312"?> <Chart Note="图表"> <Chart.Style Note="样式"> <Setter Property="BorderlineDashStyle" Value="Solid" Note="图标边框样式[NotSet:不设置线型;Dash:虚线;Solid:实线]"/> <Setter Property="BorderWidth" Value="1" Note="边框宽度"/> <Setter Property="BorderColor" Value="0,220,220,220" Note="边框颜色"/> <Setter Property="BackColor" Value="255,211,211,210" Note="背景颜色"/> <Setter Property="BackGradientStyle" Value="TopBottom" Note="背景渐变样式[None:不应用渐变;LeftRight:左右方向;TopBottom:上下;Center:从中心向外应用;DiagonalLeft:沿对角方向从左向右应用;DiagonalRight:沿对角方向从右向左应用; HorizontalCenter:沿水平方向从中心向外应用;VerticalCenter:沿垂直方向从中心向外应用]"/> <Setter Property="BackSecondaryColor" Value="255,255,249,254" Note="背景辅助颜色"/> </Chart.Style> <Chart.BorderSkin Note="边框样式"> <Setter Property="SkinStyle" Value="Emboss" Note="边框外观样式[None:不使用;Emboss:浮雕;Raised:凸起;Sunken:凹陷;FrameThin1:圆角1;FrameTitle1:圆角2]"/> <Setter Property="PageColor" Value="255,255,255,255" Note="页面背景颜色"/> </Chart.BorderSkin> <Chart.Title Enabled="false" Note="标题"> <Setter Property="Text" Value="XML线形Demo" Note="标题文字"/> <Setter Property="Docking" Value="Top" Note="停靠位置[Top;Bttom;Left;Right]"/> <Setter Property="ForeColor" Value="255,255,255" Note="字体颜色"/> <Setter Property="TextOrientation" Value="Horizontal" Note="文本方向[Horizontal:水平;Rotated90:文本旋转:90 度,成为自上向下的方向;Rotated270:文本旋转 270 度,成为自下向上的方向;Stacked:文本字符不旋转,只是逐个上下排列]"/> <Font Note="标题文字样式"> <Setter Property="Name" Value="黑体" Note="字体"/> <Setter Property="Size" Value="12" Note="字体大小"/> <Setter Property="Blod" Value="false" Note="是否采用粗体"/> </Font> </Chart.Title> <Chart.ChartArea Note="区域集合" Menu="Add" AddType="ChartArea"> <ChartArea Note="区域1" ItemName="Item1" Menu="Delete"> <CahwtArea.Attribute Note="属性"> <Setter Property="Name" Value="Area1" Note="名称"/> <Setter Property="AlignWithChartArea" Value="Area1" Note="该区域要对齐的区域名称"/> <Setter Property="BorderDashStyle" Value="Solid" Note="图标边框样式[NotSet:不设置线型;Dash:虚线;Solid:实线]"/> <Setter Property="BorderWidth" Value="1" Note="边框宽度"/> <Setter Property="BorderColor" Value="220,241,244,233" Note="边框颜色"/> <Setter Property="BackColor" Value="255,255,255,255" Note="背景颜色"/> <Setter Property="BackGradientStyle" Value="TopBottom" Note="背景渐变样式[None:不应用渐变;LeftRight:左右方向;TopBottom:上下;Center:从中心向外应用;DiagonalLeft:沿对角方向从左向右应用;DiagonalRight:沿对角方向从右向左应用;HorizontalCenter:沿水平方向从中心向外应用;VerticalCenter:沿垂直方向从中心向外应用]"/> <Setter Property="BackSecondaryColor" Value="255,255,255,255" Note="背景辅助颜色"/> </CahwtArea.Attribute> <ChartArea.Position Note="位置"> <Setter Property="X" Value="0" Note="原点X(%)"/> <Setter Property="Y" Value="3" Note="原点Y(%)"/> <Setter Property="Width" Value="97" Note="宽度(%)"/> <Setter Property="Height" Value="95" Note="高度(%)"/> </ChartArea.Position> <ChartArea.Axis Note="坐标轴"> <Axis Name="AxisX" Enabled="True" Note="AxisX" ItemName="Item1"> <Axis.Attribute Note="坐标轴属性"> <Setter Property="LineColor" Value="118,118,118" Note="线颜色"/> <Setter Property="LineDashStyle" Value="Solid" Note="线样式[NotSet:不设置线型;Dash:虚线;DashDot:由重复的点划线图案构成的直线;DashDotDot:由重复的双点划线图案构成的直线;Dot:由重复的点图案构成的直线;Solid:实线]"/> <Setter Property="LineWidth" Value="1" Note="线宽"/> <Setter Property="ArrowStyle" Value="None" Note="箭头样式[None:没有用于相关轴的箭头;Triangle:三角形状的箭头用于相关轴;SharpTriangle:尖三角形状的箭头用于相关轴;Lines:线条形箭头用于相关轴]"/> <Setter Property="IsLogarithmic" Value="False" Note="是否对数坐标"/> <Setter Property="LogarithmBase" Value="10" Note="对数基数"/> <Setter Property="IsInterlaced" Value="False" Note="是否启用带状线"/> <Setter Property="InterlacedColor" Value="100,100,100" Note="带状线间隔颜色"/> <Setter Property="Minimum" Value="" Note="最小值"/> <Setter Property="Maximum" Value="" Note="最大值"/> <Setter Property="Interval" Value="" Note="间隔值"/> <Setter Property="IsLabelAutoFit" Value="True" Note="是否自动调整轴标签"/> <Setter Property="IntervalAutoMode" Value="FixedCount" Note="间隔标志[FixedCount:始终在轴上创建固定的间隔数;VariableCount:轴间隔数取决于轴长度]"/> <Setter Property="IsMarginVisible" Value="True" Note="是否向轴添加边距"/> </Axis.Attribute> <Axis.Title Enabled="False" Note="坐标轴文字"> <Setter Property="Title" Value="坐标轴说明" Note="坐标轴文字内容"/> <Setter Property="TitleForeColor" Value="255,100,100,100" Note="坐标轴文字颜色"/> <Setter Property="TextOrientation" Value="Rotated90" Note="文本方向[Horizontal:水平;Rotated90:文本旋转 90 度,成为自上向下的方向;Rotated270:文本旋转 270 度,成为自下向上的方向;Stacked:文本字符不旋转,只是逐个上下排列]"/> <TitleFont Note="标题文字样式"> <Setter Property="Name" Value="黑体" Note="字体"/> <Setter Property="Size" Value="16" Note="字体大小"/> <Setter Property="Blod" Value="True" Note="是否采用粗体"/> </TitleFont> </Axis.Title> <Axis.Grid Note="网格线"> <Grid Name="MajorGrid" Enabled="True" Note="主要网格线" ItemName="Item1"> <Setter Property="LineDashStyle" Value="Solid" Note="网格线样式[NotSet:不设置线型;Dash:虚线;DashDot:由重复的点划线图案构成的直线;DashDotDot:由重复的双点划线图案构成的直线;Dot:由重复的点图案构成的直线;Solid:实线]"/> <Setter Property="LineWidth" Value="1" Note="线宽度"/> <Setter Property="LineColor" Value="210,210,210,210" Note="线颜色"/> <Setter Property="Interval" Value="" Note="间隔值"/> </Grid> <Grid Name="MinorGrid" Enabled="False" Note="次要网格线" ItemName="Item2"> <Setter Property="LineDashStyle" Value="Solid" Note="网格线样式[NotSet:不设置线型;Dash:虚线;DashDot:由重复的点划线图案构成的直线;DashDotDot:由重复的双点划线图案构成的直线;Dot:由重复的点图案构成的直线;Solid:实线]"/> <Setter Property="LineWidth" Value="1" Note="线宽度"/> <Setter Property="LineColor" Value="64,64,64" Note="线颜色"/> <Setter Property="Interval" Value="" Note="间隔值"/> </Grid> </Axis.Grid> <Axis.LabelStyle Enabled="True" Note="标签"> <Setter Property="ForeColor" Value="195,0,0,0" Note="字体颜色"/> <Setter Property="Angle" Value="0" Note="绘制字体所用角度"/> <Setter Property="Format" Value="MM-dd" Note="文字格式"/> <Setter Property="IsEndLabelVisible" Value="True" Note="是否显示最后一个坐标"/> <Setter Property="Interval" Value="" Note="标签间隔值"/> <Setter Property="IsStaggered" Value="True" Note="是否显示为带有偏移量"/> <Setter Property="IntervalOffset" Value="0" Note="间隔的偏移量"/> <Font Note="字体"> <Setter Property="Name" Value="黑体" Note="字体"/> <Setter Property="Size" Value="6" Note="字体大小"/> <Setter Property="Blod" Value="False" Note="是否采用粗体"/> </Font> </Axis.LabelStyle> <Axis.TickMark Note="刻度线属性"> <TickMark Name="MajorTickMark" Enabled="True" Note="主要刻度线属性" ItemName="Item1"> <Setter Property="Size" Value="0" Note="相对长度"/> <Setter Property="LineWidth" Value="1" Note="线宽"/> <Setter Property="LineColor" Value="200,200,200" Note="网格线颜色"/> <Setter Property="TickMarkStyle" Value="OutsideArea" Note="刻度线位置[None:刻度线被禁用;OutsideArea:刻度线是在图表区域外部绘制的;InsideArea:刻度线是在图表区域内部绘制的;AcrossAxis:刻度线是跨相关轴线绘制的]"/> <Setter Property="LineDashStyle" Value="Solid" Note="刻度线样式[NotSet:不设置线型;Dash:虚线;DashDot:由重复的点划线图案构成的直线;DashDotDot:由重复的双点划线图案构成的直线;Dot:由重复的点图案构成的直线;Solid:实线]"/> <Setter Property="Interval" Value="" Note="主要网格线与次要网格线间隔值"/> </TickMark> <TickMark Name="MinorTickMark" Enabled="False" Note="次要刻度线属性" ItemName="Item2"> <Setter Property="Size" Value="5" Note="相对长度"/> <Setter Property="LineColor" Value="100,100,100" Note="网格线颜色"/> <Setter Property="TickMarkStyle" Value="OutsideArea" Note="刻度线位置[None:刻度线被禁用;OutsideArea:刻度线是在图表区域外部绘制的;InsideArea:刻度线是在图表区域内部绘制的;AcrossAxis:刻度线是跨相关轴线绘制的]"/> <Setter Property="LineDashStyle" Value="Solid" Note="刻度线样式[NotSet:不设置线型;Dash:虚线;DashDot:由重复的点划线图案构成的直线;DashDotDot:由重复的双点划线图案构成的直线;Dot:由重复的点图案构成的直线;Solid:实线]"/> </TickMark> </Axis.TickMark> <Axis.ScaleView Note="视图"> <Setter Property="Zoomable" Value="true" Note="是否启用了缩放用户界面"/> <Setter Property="SmallScrollSizeType" Value="Days" Note="点击度量单位[Auto:自动确定;Number:数字形式;Years:以年为单位;Months:以月为单位;Weeks:以周为单位;Days:以天为单位;Hours:小时为单位;Minutes:以分钟为单位;Seconds:以秒为单位;Milliseconds:以毫秒为单位;NotSet:不会产生任何效果]"/> <Setter Property="SmallScrollSize" Value="1" Note="拖动小滚动尺寸"/> <Setter Property="SmallScrollMinSizeType" Value="Hours" Note="拖动度量单位[Auto:自动确定;Number:数字形式;Years:以年为单位;Months:以月为单位;Weeks:以周为单位;Days:以天为单位;Hours:小时为单位;Minutes:以分钟为单位;Seconds:以秒为单位;Milliseconds:以毫秒为单位;NotSet:不会产生任何效果]"/> <Setter Property="SmallScrollMinSize" Value="1" Note="拖动小滚动尺寸"/> </Axis.ScaleView> </Axis> <Axis Name="AxisX2" Enabled="True" Note="AxisX2" ItemName="Item2"> <Axis.Attribute Note="坐标轴属性"> <Setter Property="LineColor" Value="118,118,118" Note="线颜色[255,255,255,255]"/> <Setter Property="LineDashStyle" Value="Solid" Note="线样式[NotSet:不设置线型;Dash:虚线;DashDot:由重复的点划线图案构成的直线;DashDotDot:由重复的双点划线图案构成的直线;Dot:由重复的点图案构成的直线;Solid:实线]"/> <Setter Property="LineWidth" Value="1" Note="线宽"/> <Setter Property="ArrowStyle" Value="None" Note="箭头样式[None:没有用于相关轴的箭头;Triangle:三角形状的箭头用于相关轴;SharpTriangle:尖三角形状的箭头用于相关轴;Lines:线条形箭头用于相关轴]"/> <Setter Property="IsLogarithmic" Value="False" Note="是否对数坐标"/> <Setter Property="LogarithmBase" Value="10" Note="对数基数"/> <Setter Property="IsInterlaced" Value="False" Note="是否启用带状线"/> <Setter Property="InterlacedColor" Value="100,100,100" Note="带状线间隔颜色"/> <Setter Property="Minimum" Value="" Note="最小值"/> <Setter Property="Maximum" Value="" Note="最大值"/> <Setter Property="Interval" Value="" Note="间隔值"/> <Setter Property="IsLabelAutoFit" Value="True" Note="是否自动调整轴标签"/> <Setter Property="IntervalAutoMode" Value="FixedCount" Note="间隔标志[FixedCount:始终在轴上创建固定的间隔数;VariableCount:轴间隔数取决于轴长度]"/> <Setter Property="IsMarginVisible" Value="True" Note="是否向轴添加边距"/> </Axis.Attribute> <Axis.Title Enabled="False" Note="坐标轴文字"> <Setter Property="Title" Value="坐标轴说明" Note="坐标轴文字内容"/> <Setter Property="TitleForeColor" Value="100,100,100" Note="坐标轴文字颜色"/> <Setter Property="TextOrientation" Value="Rotated90" Note="文本方向[Horizontal:水平;Rotated90:文本旋转 90 度,成为自上向下的方向;Rotated270:文本旋转 270 度,成为自下向上的方向;Stacked:文本字符不旋转,只是逐个上下排列]"/> <TitleFont Note="标题文字样式"> <Setter Property="Name" Value="黑体" Note="字体"/> <Setter Property="Size" Value="16" Note="字体大小"/> <Setter Property="Blod" Value="True" Note="是否采用粗体"/> </TitleFont> </Axis.Title> <Axis.Grid Note="网格线"> <Grid Name="MajorGrid" Enabled="False" Note="主要网格线" ItemName="Item1"> <Setter Property="LineDashStyle" Value="Solid" Note="网格线样式[NotSet:不设置线型;Dash:虚线;DashDot:由重复的点划线图案构成的直线;DashDotDot:由重复的双点划线图案构成的直线;Dot:由重复的点图案构成的直线;Solid:实线]"/> <Setter Property="LineWidth" Value="1" Note="线宽度"/> <Setter Property="LineColor" Value="64,64,64" Note="线颜色"/> <Setter Property="Interval" Value="" Note="间隔值"/> </Grid> <Grid Name="MinorGrid" Enabled="False" Note="次要网格线" ItemName="Item2"> <Setter Property="LineDashStyle" Value="Solid" Note="网格线样式[NotSet:不设置线型;Dash:虚线;DashDot:由重复的点划线图案构成的直线;DashDotDot:由重复的双点划线图案构成的直线;Dot:由重复的点图案构成的直线;Solid:实线]"/> <Setter Property="LineWidth" Value="1" Note="线宽度"/> <Setter Property="LineColor" Value="64,64,64" Note="线颜色"/> <Setter Property="Interval" Value="" Note="间隔值"/> </Grid> </Axis.Grid> <Axis.LabelStyle Enabled="False" Note="标签"> <Setter Property="ForeColor" Value="255,255,255" Note="字体颜色"/> <Setter Property="Angle" Value="0" Note="绘制字体所用角度"/> <Setter Property="Format" Value="MM月dd日 HH时" Note="文字格式"/> <Setter Property="IsEndLabelVisible" Value="True" Note="是否显示最后一个坐标"/> <Setter Property="Interval" Value="" Note="标签间隔值"/> <Setter Property="IsStaggered" Value="True" Note="是否显示为带有偏移量"/> <Setter Property="IntervalOffset" Value="0" Note="间隔的偏移量"/> <Font Note="字体"> <Setter Property="Name" Value="黑体" Note="字体"/> <Setter Property="Size" Value="6" Note="字体大小"/> <Setter Property="Blod" Value="False" Note="是否采用粗体"/> </Font> </Axis.LabelStyle> <Axis.TickMark Note="刻度线属性"> <TickMark Name="MajorTickMark" Enabled="False" Note="主要刻度线属性" ItemName="Item1"> <Setter Property="Size" Value="0" Note="相对长度"/> <Setter Property="LineWidth" Value="1" Note="线宽"/> <Setter Property="LineColor" Value="200,200,200" Note="网格线颜色"/> <Setter Property="TickMarkStyle" Value="OutsideArea" Note="刻度线位置[None:刻度线被禁用;OutsideArea:刻度线是在图表区域外部绘制的;InsideArea:刻度线是在图表区域内部绘制的;AcrossAxis:刻度线是跨相关轴线绘制的]"/> <Setter Property="LineDashStyle" Value="Solid" Note="刻度线样式[NotSet:不设置线型;Dash:虚线;DashDot:由重复的点划线图案构成的直线;DashDotDot:由重复的双点划线图案构成的直线;Dot:由重复的点图案构成的直线;Solid:实线]"/> <Setter Property="Interval" Value="" Note="主要网格线与次要网格线间隔值"/> </TickMark> <TickMark Name="MinorTickMark" Enabled="False" Note="次要刻度线属性" ItemName="Item2"> <Setter Property="Size" Value="5" Note="相对长度"/> <Setter Property="LineColor" Value="100,100,100" Note="网格线颜色"/> <Setter Property="TickMarkStyle" Value="OutsideArea" Note="刻度线位置[None:刻度线被禁用;OutsideArea:刻度线是在图表区域外部绘制的;InsideArea:刻度线是在图表区域内部绘制的;AcrossAxis:刻度线是跨相关轴线绘制的]"/> <Setter Property="LineDashStyle" Value="Solid" Note="刻度线样式[NotSet:不设置线型;Dash:虚线;DashDot:由重复的点划线图案构成的直线;DashDotDot:由重复的双点划线图案构成的直线;Dot:由重复的点图案构成的直线;Solid:实线]"/> </TickMark> </Axis.TickMark> <Axis.ScaleView Note="视图"> <Setter Property="Zoomable" Value="False" Note="是否启用了缩放用户界面"/> <Setter Property="SmallScrollSizeType" Value="Days" Note="点击度量单位[Auto:自动确定;Number:数字形式;Years:以年为单位;Months:以月为单位;Weeks:以周为单位;Days:以天为单位;Hours:小时为单位;Minutes:以分钟为单位;Seconds:以秒为单位;Milliseconds:以毫秒为单位;NotSet:不会产生任何效果]"/> <Setter Property="SmallScrollSize" Value="1" Note="拖动小滚动尺寸"/> <Setter Property="SmallScrollMinSizeType" Value="Hours" Note="拖动度量单位[Auto:自动确定;Number:数字形式;Years:以年为单位;Months:以月为单位;Weeks:以周为单位;Days:以天为单位;Hours:小时为单位;Minutes:以分钟为单位;Seconds:以秒为单位;Milliseconds:以毫秒为单位;NotSet:不会产生任何效果]"/> <Setter Property="SmallScrollMinSize" Value="1" Note="拖动小滚动尺寸"/> </Axis.ScaleView> </Axis> <Axis Name="AxisY" Enabled="True" Note="AxisY" ItemName="Item3"> <Axis.Attribute Note="坐标轴属性"> <Setter Property="LineColor" Value="118,118,118" Note="线颜色"/> <Setter Property="LineDashStyle" Value="Solid" Note="线样式[NotSet:不设置线型;Dash:虚线;DashDot:由重复的点划线图案构成的直线;DashDotDot:由重复的双点划线图案构成的直线;Dot:由重复的点图案构成的直线;Solid:实线]"/> <Setter Property="LineWidth" Value="1" Note="线宽"/> <Setter Property="ArrowStyle" Value="None" Note="箭头样式[None:没有用于相关轴的箭头;Triangle:三角形状的箭头用于相关轴;SharpTriangle:尖三角形状的箭头用于相关轴;Lines:线条形箭头用于相关轴]"/> <Setter Property="IsLogarithmic" Value="False" Note="是否对数坐标"/> <Setter Property="LogarithmBase" Value="10" Note="对数基数"/> <Setter Property="IsInterlaced" Value="False" Note="是否启用带状线"/> <Setter Property="InterlacedColor" Value="100,100,100" Note="带状线间隔颜色"/> <Setter Property="Minimum" Value="" Note="最小值"/> <Setter Property="Maximum" Value="" Note="最大值"/> <Setter Property="Interval" Value="" Note="间隔值"/> <Setter Property="IsLabelAutoFit" Value="True" Note="是否自动调整轴标签"/> <Setter Property="IntervalAutoMode" Value="FixedCount" Note="间隔标志[FixedCount:始终在轴上创建固定的间隔数;VariableCount:轴间隔数取决于轴长度]"/> <Setter Property="IsMarginVisible" Value="True" Note="是否向轴添加边距"/> </Axis.Attribute> <Axis.Title Enabled="False" Note="坐标轴文字"> <Setter Property="Title" Value="坐标轴说明" Note="坐标轴文字内容"/> <Setter Property="TitleForeColor" Value="100,100,100" Note="坐标轴文字颜色"/> <Setter Property="TextOrientation" Value="Rotated90" Note="文本方向[Horizontal:水平;Rotated90:文本旋转 90 度,成为自上向下的方向;Rotated270:文本旋转 270 度,成为自下向上的方向;Stacked:文本字符不旋转,只是逐个上下排列]"/> <TitleFont Note="标题文字样式"> <Setter Property="Name" Value="黑体" Note="字体"/> <Setter Property="Size" Value="16" Note="字体大小"/> <Setter Property="Blod" Value="True" Note="是否采用粗体"/> </TitleFont> </Axis.Title> <Axis.Grid Note="网格线"> <Grid Name="MajorGrid" Enabled="True" Note="主要网格线" ItemName="Item1"> <Setter Property="LineDashStyle" Value="Solid" Note="网格线样式[NotSet:不设置线型;Dash:虚线;DashDot:由重复的点划线图案构成的直线;DashDotDot:由重复的双点划线图案构成的直线;Dot:由重复的点图案构成的直线;Solid:实线]"/> <Setter Property="LineWidth" Value="1" Note="线宽度"/> <Setter Property="LineColor" Value="200,200,200,200" Note="线颜色"/> <Setter Property="Interval" Value="" Note="间隔值"/> </Grid> <Grid Name="MinorGrid" Enabled="False" Note="次要网格线" ItemName="Item2"> <Setter Property="LineDashStyle" Value="Solid" Note="网格线样式[NotSet:不设置线型;Dash:虚线;DashDot:由重复的点划线图案构成的直线;DashDotDot:由重复的双点划线图案构成的直线;Dot:由重复的点图案构成的直线;Solid:实线]"/> <Setter Property="LineWidth" Value="1" Note="线宽度"/> <Setter Property="LineColor" Value="255,190,190,190" Note="线颜色"/> <Setter Property="Interval" Value="" Note="间隔值"/> </Grid> </Axis.Grid> <Axis.LabelStyle Enabled="True" Note="标签"> <Setter Property="ForeColor" Value="195,0,0,0" Note="字体颜色"/> <Setter Property="Angle" Value="0" Note="绘制字体所用角度"/> <Setter Property="Format" Value="" Note="文字格式"/> <Setter Property="IsEndLabelVisible" Value="True" Note="是否显示最后一个坐标"/> <Setter Property="Interval" Value="" Note="标签间隔值"/> <Setter Property="IsStaggered" Value="True" Note="是否显示为带有偏移量"/> <Setter Property="IntervalOffset" Value="0" Note="间隔的偏移量"/> <Font Note="字体"> <Setter Property="Name" Value="黑体" Note="字体"/> <Setter Property="Size" Value="6" Note="字体大小"/> <Setter Property="Blod" Value="False" Note="是否采用粗体"/> </Font> </Axis.LabelStyle> <Axis.TickMark Note="刻度线属性"> <TickMark Name="MajorTickMark" Enabled="True" Note="主要刻度线属性" ItemName="Item1"> <Setter Property="Size" Value="0" Note="相对长度"/> <Setter Property="LineWidth" Value="1" Note="线宽"/> <Setter Property="LineColor" Value="255,240,222,242" Note="网格线颜色"/> <Setter Property="TickMarkStyle" Value="OutsideArea" Note="刻度线位置[None:刻度线被禁用;OutsideArea:刻度线是在图表区域外部绘制的;InsideArea:刻度线是在图表区域内部绘制的;AcrossAxis:刻度线是跨相关轴线绘制的]"/> <Setter Property="LineDashStyle" Value="Solid" Note="刻度线样式[NotSet:不设置线型;Dash:虚线;DashDot:由重复的点划线图案构成的直线;DashDotDot:由重复的双点划线图案构成的直线;Dot:由重复的点图案构成的直线;Solid:实线]"/> <Setter Property="Interval" Value="" Note="主要网格线与次要网格线间隔值"/> </TickMark> <TickMark Name="MinorTickMark" Enabled="False" Note="次要刻度线属性" ItemName="Item2"> <Setter Property="Size" Value="5" Note="相对长度"/> <Setter Property="LineColor" Value="100,100,100" Note="网格线颜色"/> <Setter Property="TickMarkStyle" Value="OutsideArea" Note="刻度线位置[None:刻度线被禁用;OutsideArea:刻度线是在图表区域外部绘制的;InsideArea:刻度线是在图表区域内部绘制的;AcrossAxis:刻度线是跨相关轴线绘制的]"/> <Setter Property="LineDashStyle" Value="Solid" Note="刻度线样式[NotSet:不设置线型;Dash:虚线;DashDot:由重复的点划线图案构成的直线;DashDotDot:由重复的双点划线图案构成的直线;Dot:由重复的点图案构成的直线;Solid:实线]"/> </TickMark> </Axis.TickMark> <Axis.ScaleView Note="视图"> <Setter Property="Zoomable" Value="false" Note="是否启用了缩放用户界面"/> <Setter Property="SmallScrollSizeType" Value="Days" Note="点击度量单位[Auto:自动确定;Number:数字形式;Years:以年为单位;Months:以月为单位;Weeks:以周为单位;Days:以天为单位;Hours:小时为单位;Minutes:以分钟为单位;Seconds:以秒为单位;Milliseconds:以毫秒为单位;NotSet:不会产生任何效果]"/> <Setter Property="SmallScrollSize" Value="1" Note="拖动小滚动尺寸"/> <Setter Property="SmallScrollMinSizeType" Value="Hours" Note="拖动度量单位[Auto:自动确定;Number:数字形式;Years:以年为单位;Months:以月为单位;Weeks:以周为单位;Days:以天为单位;Hours:小时为单位;Minutes:以分钟为单位;Seconds:以秒为单位;Milliseconds:以毫秒为单位;NotSet:不会产生任何效果]"/> <Setter Property="SmallScrollMinSize" Value="1" Note="拖动小滚动尺寸"/> </Axis.ScaleView> </Axis> <Axis Name="AxisY2" Enabled="True" Note="AxisY2" ItemName="Item4"> <Axis.Attribute Note="坐标轴属性"> <Setter Property="LineColor" Value="118,118,118" Note="线颜色"/> <Setter Property="LineDashStyle" Value="Solid" Note="线样式[NotSet:不设置线型;Dash:虚线;DashDot:由重复的点划线图案构成的直线;DashDotDot:由重复的双点划线图案构成的直线;Dot:由重复的点图案构成的直线;Solid:实线]"/> <Setter Property="LineWidth" Value="1" Note="线宽"/> <Setter Property="ArrowStyle" Value="None" Note="箭头样式[None:没有用于相关轴的箭头;Triangle:三角形状的箭头用于相关轴;SharpTriangle:尖三角形状的箭头用于相关轴;Lines:线条形箭头用于相关轴]"/> <Setter Property="IsLogarithmic" Value="False" Note="是否对数坐标"/> <Setter Property="LogarithmBase" Value="10" Note="对数基数"/> <Setter Property="IsInterlaced" Value="False" Note="是否启用带状线"/> <Setter Property="InterlacedColor" Value="100,100,100" Note="带状线间隔颜色"/> <Setter Property="Minimum" Value="" Note="最小值"/> <Setter Property="Maximum" Value="" Note="最大值"/> <Setter Property="Interval" Value="" Note="间隔值"/> <Setter Property="IsLabelAutoFit" Value="True" Note="是否自动调整轴标签"/> <Setter Property="IntervalAutoMode" Value="FixedCount" Note="间隔标志[FixedCount:始终在轴上创建固定的间隔数;VariableCount:轴间隔数取决于轴长度]"/> <Setter Property="IsMarginVisible" Value="True" Note="是否向轴添加边距"/> </Axis.Attribute> <Axis.Title Enabled="False" Note="坐标轴文字"> <Setter Property="Title" Value="坐标轴说明" Note="坐标轴文字内容"/> <Setter Property="TitleForeColor" Value="100,100,100" Note="坐标轴文字颜色"/> <Setter Property="TextOrientation" Value="Rotated90" Note="文本方向[Horizontal:水平;Rotated90:文本旋转 90 度,成为自上向下的方向;Rotated270:文本旋转 270 度,成为自下向上的方向;Stacked:文本字符不旋转,只是逐个上下排列]"/> <TitleFont Note="标题文字样式"> <Setter Property="Name" Value="黑体" Note="字体"/> <Setter Property="Size" Value="16" Note="字体大小"/> <Setter Property="Blod" Value="True" Note="是否采用粗体"/> </TitleFont> </Axis.Title> <Axis.Grid Note="网格线"> <Grid Name="MajorGrid" Enabled="False" Note="主要网格线" ItemName="Item1"> <Setter Property="LineDashStyle" Value="Solid" Note="网格线样式[NotSet:不设置线型;Dash:虚线;DashDot:由重复的点划线图案构成的直线;DashDotDot:由重复的双点划线图案构成的直线;Dot:由重复的点图案构成的直线;Solid:实线]"/> <Setter Property="LineWidth" Value="1" Note="线宽度"/> <Setter Property="LineColor" Value="64,64,64" Note="线颜色"/> <Setter Property="Interval" Value="" Note="间隔值"/> </Grid> <Grid Name="MinorGrid" Enabled="False" Note="次要网格线" ItemName="Item2"> <Setter Property="LineDashStyle" Value="Solid" Note="网格线样式[NotSet:不设置线型;Dash:虚线;DashDot:由重复的点划线图案构成的直线;DashDotDot:由重复的双点划线图案构成的直线;Dot:由重复的点图案构成的直线;Solid:实线]"/> <Setter Property="LineWidth" Value="1" Note="线宽度"/> <Setter Property="LineColor" Value="64,64,64" Note="线颜色"/> <Setter Property="Interval" Value="" Note="间隔值"/> </Grid> </Axis.Grid> <Axis.LabelStyle Enabled="False" Note="标签"> <Setter Property="ForeColor" Value="255,255,255" Note="字体颜色"/> <Setter Property="Angle" Value="0" Note="绘制字体所用角度"/> <Setter Property="Format" Value="MM月dd日 HH时" Note="文字格式"/> <Setter Property="IsEndLabelVisible" Value="True" Note="是否显示最后一个坐标"/> <Setter Property="Interval" Value="" Note="标签间隔值"/> <Setter Property="IsStaggered" Value="True" Note="是否显示为带有偏移量"/> <Setter Property="IntervalOffset" Value="0" Note="间隔的偏移量"/> <Font Note="字体"> <Setter Property="Name" Value="黑体" Note="字体"/> <Setter Property="Size" Value="6" Note="字体大小"/> <Setter Property="Blod" Value="False" Note="是否采用粗体"/> </Font> </Axis.LabelStyle> <Axis.TickMark Note="刻度线属性"> <TickMark Name="MajorTickMark" Enabled="False" Note="主要刻度线属性" ItemName="Item1"> <Setter Property="Size" Value="0" Note="相对长度"/> <Setter Property="LineWidth" Value="1" Note="线宽"/> <Setter Property="LineColor" Value="200,200,200" Note="网格线颜色"/> <Setter Property="TickMarkStyle" Value="OutsideArea" Note="刻度线位置[None:刻度线被禁用;OutsideArea:刻度线是在图表区域外部绘制的;InsideArea:刻度线是在图表区域内部绘制的;AcrossAxis:刻度线是跨相关轴线绘制的]"/> <Setter Property="LineDashStyle" Value="Solid" Note="刻度线样式[NotSet:不设置线型;Dash:虚线;DashDot:由重复的点划线图案构成的直线;DashDotDot:由重复的双点划线图案构成的直线;Dot:由重复的点图案构成的直线;Solid:实线]"/> <Setter Property="Interval" Value="" Note="主要网格线与次要网格线间隔值"/> </TickMark> <TickMark Name="MinorTickMark" Enabled="False" Note="次要刻度线属性" ItemName="Item2"> <Setter Property="Size" Value="5" Note="相对长度"/> <Setter Property="LineColor" Value="100,100,100" Note="网格线颜色"/> <Setter Property="TickMarkStyle" Value="OutsideArea" Note="刻度线位置[None:刻度线被禁用;OutsideArea:刻度线是在图表区域外部绘制的;InsideArea:刻度线是在图表区域内部绘制的;AcrossAxis:刻度线是跨相关轴线绘制的]"/> <Setter Property="LineDashStyle" Value="Solid" Note="刻度线样式[NotSet:不设置线型;Dash:虚线;DashDot:由重复的点划线图案构成的直线;DashDotDot:由重复的双点划线图案构成的直线;Dot:由重复的点图案构成的直线;Solid:实线]"/> </TickMark> </Axis.TickMark> <Axis.ScaleView Note="视图"> <Setter Property="Zoomable" Value="false" Note="是否启用了缩放用户界面"/> <Setter Property="SmallScrollSizeType" Value="Days" Note="点击度量单位[Auto:自动确定;Number:数字形式;Years:以年为单位;Months:以月为单位;Weeks:以周为单位;Days:以天为单位;Hours:小时为单位;Minutes:以分钟为单位;Seconds:以秒为单位;Milliseconds:以毫秒为单位;NotSet:不会产生任何效果]"/> <Setter Property="SmallScrollSize" Value="1" Note="拖动小滚动尺寸"/> <Setter Property="SmallScrollMinSizeType" Value="Hours" Note="拖动度量单位[Auto:自动确定;Number:数字形式;Years:以年为单位;Months:以月为单位;Weeks:以周为单位;Days:以天为单位;Hours:小时为单位;Minutes:以分钟为单位;Seconds:以秒为单位;Milliseconds:以毫秒为单位;NotSet:不会产生任何效果]"/> <Setter Property="SmallScrollMinSize" Value="1" Note="拖动小滚动尺寸"/> </Axis.ScaleView> </Axis> </ChartArea.Axis> <ChartArea.Area3DStyle Enabled="False" Note="三维效果"/> <ChartArea.Cursor Note="光标"> <Cursor Name="CursorX" Note="x轴方向光标" ItemName="Item1"> <Setter Property="AxisType" Value="Primary" Note="光标附加到的轴的类型[Primary:主轴;Secondary:辅助轴]"/> <Setter Property="IsUserEnabled" Value="False" Note="标志启用或禁用光标用户界面"/> <Setter Property="LineColor" Value="100,100,100" Note="光标线条颜色"/> <Setter Property="LineWidth" Value="1" Note="光标的线条宽度"/> <Setter Property="LineDashStyle" Value="Solid" Note="光标线条的样式[NotSet:不设置线型;Dash:虚线;DashDot:由重复的点划线图案构成的直线;DashDotDot:由重复的双点划线图案构成的直线;Dot:由重复的点图案构成的直线;Solid:实线]"/> <Setter Property="IsUserSelectionEnabled" Value="True" Note="启用或禁用范围选择用户界面"/> <Setter Property="SelectionColor" Value="100,0,0,0" Note="突出显示某一范围数据的半透明颜色"/> <Setter Property="IntervalType" Value="Hours" Note="轴的光标和所选范围的间隔类型[Auto:自动确定;Number:数字形式;Years:以年为单位;Months:以月为单位;Weeks:以周为单位;Days:以天为单位;Hours:小时为单位;Minutes:以分钟为单位;Seconds:以秒为单位;Milliseconds:以毫秒为单位;NotSet:不会产生任何效果]"/> <Setter Property="Interval" Value="1" Note="光标间隔"/> <Setter Property="IntervalOffset" Value="1" Note="光标和所选范围的间隔偏移量类型"/> <Setter Property="IntervalOffsetType" Value="Hours" Note="光标和所选范围的间隔偏移量类型[Auto:自动确定;Number:数字形式;Years:以年为单位;Months:以月为单位;Weeks:以周为单位;Days:以天为单位;Hours:小时为单位;Minutes:以分钟为单位;Seconds:以秒为单位;Milliseconds:以毫秒为单位;NotSet:不会产生任何效果]"/> </Cursor> <Cursor Name="CursorY" Note="y轴方向光标" ItemName="Item2"> <Setter Property="AxisType" Value="Primary" Note="光标附加到的轴的类型[Primary:主轴;Secondary:辅助轴]"/> <Setter Property="IsUserEnabled" Value="False" Note="标志启用或禁用光标用户界面"/> <Setter Property="LineColor" Value="100,100,100" Note="光标线条颜色"/> <Setter Property="LineWidth" Value="1" Note="光标的线条宽度"/> <Setter Property="LineDashStyle" Value="Solid" Note="光标线条的样式[NotSet:不设置线型;Dash:虚线;DashDot:由重复的点划线图案构成的直线;DashDotDot:由重复的双点划线图案构成的直线;Dot:由重复的点图案构成的直线;Solid:实线]"/> <Setter Property="IsUserSelectionEnabled" Value="False" Note="启用或禁用范围选择用户界面"/> <Setter Property="SelectionColor" Value="100,0,0,0" Note="突出显示某一范围数据的半透明颜色"/> <Setter Property="IntervalType" Value="Hours" Note="轴的光标和所选范围的间隔类型[Auto:自动确定;Number:数字形式;Years:以年为单位;Months:以月为单位;Weeks:以周为单位;Days:以天为单位;Hours:小时为单位;Minutes:以分钟为单位;Seconds:以秒为单位;Milliseconds:以毫秒为单位;NotSet:不会产生任何效果]"/> <Setter Property="Interval" Value="1" Note="光标间隔"/> <Setter Property="IntervalOffset" Value="1" Note="光标和所选范围的间隔偏移量类型"/> <Setter Property="IntervalOffsetType" Value="Hours" Note="光标和所选范围的间隔偏移量类型[Auto:自动确定;Number:数字形式;Years:以年为单位;Months:以月为单位;Weeks:以周为单位;Days:以天为单位;Hours:小时为单位;Minutes:以分钟为单位;Seconds:以秒为单位;Milliseconds:以毫秒为单位;NotSet:不会产生任何效果]"/> </Cursor> </ChartArea.Cursor> </ChartArea> </Chart.ChartArea> <Chart.Series Note="序列集合" Menu="Add" AddType="Series"> <Series Note="序列1" ItemName="Item1" Menu="Delete"> <Series.Attribute Note="属性"> <Setter Property="Name" Value="Series1" Note="名称"/> <Setter Property="ChartArea" Value="Area1" Note="所在区域名称"/> <Setter Property="Legend" Value="Default" Note="所在图例名称/提示分组"/> <Setter Property="ChartType" Value="Line" Note="序列类型[Line:折线图;Spline:平滑线;StepLine:阶梯线;FastLine:快速扫描线;Column:柱子;Area:面积图;Point:散点;Bubble:气泡;RangeColumn:范围柱]"/> <Setter Property="BorderWidth" Value="2" Note="数据点边框宽度"/> <Setter Property="BorderColor" Value="0,110,152" Note="数据点边框颜色"/> <Setter Property="Color" Value="0,110,152" Note="数据点颜色"/> <Setter Property="BackGradientStyle" Value="TopBottom" Note="数据点背景渐变样式[None:不应用渐变;LeftRight:左右方向;TopBottom:上下;Center:从中心向外应用;DiagonalLeft:沿对角方向从左向右应用;DiagonalRight:沿对角方向从右向左应用;HorizontalCenter:沿水平方向从中心向外应用;VerticalCenter:沿垂直方向从中心向外应用]"/> <Setter Property="BackSecondaryColor" Value="100,100,100" Note="辅助背景颜色"/> <Setter Property="ShadowColor" Value="10,10,10" Note="数据点阴影颜色"/> <Setter Property="ShadowOffset" Value="1" Note="数据点阴影偏离量"/> <Setter Property="IsValueShownAsLabel" Value="False" Note="是否使用标签显示数据点值"/> <Setter Property="XAxisType" Value="Primary" Note="x值轴类型[Primary:主轴;Secondary:辅轴]"/> <Setter Property="YAxisType" Value="Primary" Note="y值轴类型[Primary:主轴;Secondary:辅轴]"/> <Setter Property="XValueType" Value="DateTime" Note="x轴数据类型[Double;Single;Int32;String;DateTime]"/> <Setter Property="YValueType" Value="Double" Note="y轴数据类型[Double;Single;Int32;String;DateTime]"/> </Series.Attribute> <Series.Custom Note="自定义"> <Setter Property="DrawingStyle" Value="Cylinder" Note="数据点绘制方式,一般为柱子和范围柱时添加[Default:默认;Emboss:修饰边框;Cylinder:圆柱]"/> <Setter Property="PointWidth" Value="2" Note="柱子和范围柱宽度占柱子可分配宽度的百分比"/> <Setter Property="PixelPointWidth" Value="20" Note="柱子和范围柱宽度"/> </Series.Custom> <Series.Marker Enabled="False" Note="标记"> <Setter Property="MarkerStyle" Value="Circle" Note="标记样式[Square:正方形标记;Circle:圆形标记;Diamond:菱形标记;Triangle:三角形标记;Cross:十字形标记;Star4:五角星形标记;Star6:六角星形;Star10:十角星形标记]"/> <Setter Property="MarkerSize" Value="5" Note="标记大小"/> <Setter Property="MarkerColor" Value="255,255,255" Note="标记填充颜色"/> <Setter Property="MarkerBorderColor" Value="0,110,152" Note="标记边框颜色"/> <Setter Property="MarkerBorderWidth" Value="2" Note="标记边框宽度"/> </Series.Marker> <Series.Dalta Enabled="False" Note="震动幅度"> <Setter Property="DaltaValue" Value="100" Note="震动幅度"/> <Setter Property="AvgConst" Value="100" Note="均值常量(柱子为空)"/> <Setter Property="AvgFormat" Value="F0" Note="均值调整格式(柱子为空)"/> </Series.Dalta> </Series> <Series Note="序列2" ItemName="Item2" Menu="Delete"> <Series.Attribute Note="属性"> <Setter Property="Name" Value="Series2" Note="名称"/> <Setter Property="ChartArea" Value="Area1" Note="所在区域名称"/> <Setter Property="Legend" Value="Default" Note="所在图例名称/提示分组"/> <Setter Property="ChartType" Value="Line" Note="序列类型[Line:折线图;Spline:平滑线;StepLine:阶梯线;FastLine:快速扫描线;Column:柱子;Area:面积图;Point:散点;Bubble:气泡;RangeColumn:范围柱]"/> <Setter Property="BorderWidth" Value="2" Note="数据点边框宽度"/> <Setter Property="BorderColor" Value="255,236,203,97" Note="数据点边框颜色"/> <Setter Property="Color" Value="255,236,203,97" Note="数据点颜色"/> <Setter Property="BackGradientStyle" Value="TopBottom" Note="数据点背景渐变样式[None:不应用渐变;LeftRight:左右方向;TopBottom:上下;Center:从中心向外应用;DiagonalLeft:沿对角方向从左向右应用;DiagonalRight:沿对角方向从右向左应用;HorizontalCenter:沿水平方向从中心向外应用;VerticalCenter:沿垂直方向从中心向外应用]"/> <Setter Property="BackSecondaryColor" Value="100,100,100" Note="辅助背景颜色"/> <Setter Property="ShadowColor" Value="10,10,10" Note="数据点阴影颜色"/> <Setter Property="ShadowOffset" Value="1" Note="数据点阴影偏离量"/> <Setter Property="IsValueShownAsLabel" Value="False" Note="是否使用标签显示数据点值"/> <Setter Property="XAxisType" Value="Primary" Note="x值轴类型[Primary:主轴;Secondary:辅轴]"/> <Setter Property="YAxisType" Value="Primary" Note="y值轴类型[Primary:主轴;Secondary:辅轴]"/> <Setter Property="XValueType" Value="DateTime" Note="x轴数据类型[Double;Single;Int32;String;DateTime]"/> <Setter Property="YValueType" Value="Double" Note="y轴数据类型[Double;Single;Int32;String;DateTime]"/> </Series.Attribute> <Series.Custom Note="自定义"> <Setter Property="DrawingStyle" Value="Cylinder" Note="数据点绘制方式,一般为柱子和范围柱时添加[Default:默认;Emboss:修饰边框;Cylinder:圆柱]"/> <Setter Property="PointWidth" Value="2" Note="柱子和范围柱宽度占柱子可分配宽度的百分比"/> <Setter Property="PixelPointWidth" Value="20" Note="柱子和范围柱宽度"/> </Series.Custom> <Series.Marker Enabled="False" Note="标记"> <Setter Property="MarkerStyle" Value="Circle" Note="标记样式[Square:正方形标记;Circle:圆形标记;Diamond:菱形标记;Triangle:三角形标记;Cross:十字形标记;Star4:五角星形标记;Star6:六角星形;Star10:十角星形标记]"/> <Setter Property="MarkerSize" Value="5" Note="标记大小"/> <Setter Property="MarkerColor" Value="255,255,255" Note="标记填充颜色"/> <Setter Property="MarkerBorderColor" Value="255,236,203,97" Note="标记边框颜色"/> <Setter Property="MarkerBorderWidth" Value="2" Note="标记边框宽度"/> </Series.Marker> <Series.Dalta Enabled="False" Note="震动幅度"> <Setter Property="DaltaValue" Value="100" Note="震动幅度"/> <Setter Property="AvgConst" Value="100" Note="均值常量(柱子为空)"/> <Setter Property="AvgFormat" Value="F0" Note="均值调整格式(柱子为空)"/> </Series.Dalta> </Series> </Chart.Series> <Chart.ToopTip Note="提示信息"> <Setter Property="TipWidth" Value="150" Note="宽度"/> <Setter Property="TipBackColor" Value="150,0,0,0" Note="背景颜色"/> <Setter Property="xFontName" Value="黑体" Note="x值字体名称"/> <Setter Property="xFontSize" Value="8" Note="x值字体大小"/> <Setter Property="xFontColor" Value="255,200,10" Note="x值字体颜色"/> <Setter Property="xFontBold" Value="False" Note="x值字体是否粗体"/> <Setter Property="xFontFormat" Value="MM月dd日 HH时mm分" Note="x值格式化字符串"/> <Setter Property="hLineColor" Value="255,255,255" Note="横线颜色"/> <Setter Property="hLineWidth" Value="1" Note="横线宽度"/> <Setter Property="yFontName" Value="黑体" Note="y值字体名称"/> <Setter Property="yFontSize" Value="10" Note="y值字体大小"/> <Setter Property="yFontColor" Value="255,255,255" Note="y值字体颜色"/> <Setter Property="yFontBold" Value="False" Note="y值字体是否粗体"/> <Setter Property="TitleColor" Value="255,0,0" Note="标题头部颜色"/> </Chart.ToopTip> <Chart.Custom Note="自定义"> <Lines Note="线集合" Menu="Add" AddType="Line"> <Line Enabled="false" Note="线1" ItemName="Item1" Menu="Delete"> <Setter Property="Direct" Value="h" Note="方向[h:横线;v:竖线]"/> <Setter Property="areaName" Value="Area1" Note="所在区域名称"/> <Setter Property="X" Value="20111122" Note="X位置"/> <Setter Property="Y" Value="100" Note="Y位置"/> <Setter Property="IsAb" Value="False" Note="是否绝对坐标值"/> <Setter Property="style" Value="DotLine" Note="线类型[Line:实线;DotLine:虚线;DashLine:虚线段]"/> <Setter Property="width" Value="1" Note="线宽度"/> <Setter Property="color" Value="255,100,0" Note="线颜色"/> </Line> <Line Enabled="false" Note="线2" ItemName="Item2" Menu="Delete"> <Setter Property="Direct" Value="v" Note="方向[h:横线;v:竖线]"/> <Setter Property="areaName" Value="Area1" Note="所在区域名称"/> <Setter Property="X" Value="20111122" Note="X位置"/> <Setter Property="Y" Value="100" Note="Y位置"/> <Setter Property="IsAb" Value="False" Note="是否绝对坐标值"/> <Setter Property="style" Value="DotLine" Note="线类型[Line:实线;DotLine:虚线;DashLine:虚线段]"/> <Setter Property="width" Value="1" Note="线宽度"/> <Setter Property="color" Value="255,100,0" Note="线颜色"/> </Line> </Lines> <Images Note="图片集合" Menu="Add" AddType="Image"> <Image Enabled="false" Note="图片1" ItemName="Item1" Menu="Delete"> <Setter Property="name" Value="Area1" Note="所在区域名称"/> <Setter Property="X" Value="20111122" Note="x值"/> <Setter Property="Y" Value="100" Note="y值"/> <Setter Property="IsAb" Value="False" Note="是否绝对坐标值"/> <Setter Property="path" Value="..\..\Images\over_8.png" Note="图片路径"/> </Image> </Images> <Letters Note="停靠多彩文字"> <Letter Docking="Top" Note="上面" ItemName="Item1" Menu="Add" AddType="String"/> <Letter Docking="Bttom" Note="下面" ItemName="Item2" Menu="Add" AddType="String"/> <Letter Docking="Left" Note="左侧" ItemName="Item3" Menu="Add" AddType="String"/> <Letter Docking="Right" Note="右侧" ItemName="Item4" Menu="Add" AddType="String"> <String Note="文字1" ItemName="Item1" Menu="Delete"> <Setter Property="areaName" Value="Area1" Note="区域名称"/> <Setter Property="rotateTransform" Value="270" Note="旋转角度"/> <Setter Property="padding" Value="15" Note="内边距"/> <Setter Property="Text" Value="F107" Note="内容"/> <Setter Property="ForeColor" Value="198,29,196,208" Note="颜色"/> <Setter Property="Name" Value="Arial Rounded MT Bold" Note="字体"/> <Setter Property="Size" Value="10" Note="字体大小"/> <Setter Property="Blod" Value="False" Note="是否采用粗体"/> </String> </Letter> </Letters> <Characters Note="相对位置文字" Menu="Add" AddType="Character"> <Character Enabled="false" Note="文字1" ItemName="Item1" Menu="Delete"> <Setter Property="areaName" Value="Area1" Note="区域名称"/> <Setter Property="Rtf" Value="0" Note="旋转角度[0:0;90:90;270:270]"/> <Setter Property="X" Value="Max" Note="x值[Min:Min;Center:Center;Max:Max]" Edited="True"/> <Setter Property="Xpadding" Value="0" Note="x值偏移量"/> <Setter Property="Y" Value="Center" Note="y值[Min:Min;Center:Center;Max:Max]" Edited="True"/> <Setter Property="Ypadding" Value="0" Note="y值偏移量"/> <Setter Property="content" Value="Character" Note="内容"/> <Setter Property="color" Value="198,29,196,208" Note="颜色"/> <Setter Property="name" Value="Arial Rounded MT Bold" Note="字体"/> <Setter Property="size" Value="10" Note="字体大小"/> <Setter Property="bold" Value="False" Note="是否采用粗体"/> </Character> </Characters> <MultiColorsBars Note="彩色指示条" Menu="Add" AddType="ColorBar"/> <SeriesColors Note="多彩序列" Menu="Add" AddType="SeriesColor"/> </Chart.Custom> </Chart>
利用反射解析属性核心代码:
View Code
/// <summary> /// 循环属性赋值 /// </summary> /// <param name="xe">属性节点的父节点</param> /// <param name="ob">要赋值的对象</param> /// <param name="t">要赋值对象type</param> private void mySet(IEnumerable<XElement> xeSetters, object ob, Type t) { if (object.Equals(xeSetters, null)) { return; } foreach (XElement elSetter in xeSetters) { string Property = (string)elSetter.Attribute("Property").Value; string Value = (string)elSetter.Attribute("Value").Value; mySet(ob, t, Property, Value); } } #region 属性赋值 /// <summary> /// 属性赋值 /// </summary> /// <param name="ob">要赋值的对象</param> /// <param name="t">要赋值对象type</param> /// <param name="p">属性</param> /// <param name="v">值</param> private void mySet(object ob, Type t, string p, string v) { foreach (MemberInfo mi in t.GetMember(p)) { PropertyInfo pi = t.GetProperty(mi.Name); if (!object.Equals(pi, null)) { try { pi.SetValue(ob, myConvert(pi.PropertyType, v), null); } catch (Exception e) { string ss = e.Message; } } } } #endregion #region 字符串转为对应Type /// <summary> /// 字符串转为对应Type /// </summary> /// <param name="t">Type</param> /// <param name="value">字符串</param> /// <returns>object</returns> private object myConvert(Type t, string value) { object ob = null; if (t == typeof(System.Int32)) { ob = Convert.ToInt32(value); } else if (t == typeof(System.Drawing.Color)) { ob = FamtStringColor(value); } else if (t == typeof(System.Double)) { ob = Convert.ToDouble(value); } else if (t == typeof(System.Single)) { ob = Convert.ToSingle(value); } else if (t == typeof(System.String)) { ob = value; } else if (t == typeof(System.Boolean)) { ob = Convert.ToBoolean(value); } else { ob = Enum.Parse(t, value, false); } return ob; } #endregion
解析xml调用属性设置代码(牵扯到太多业务):
View Code
#region 通过Xml方式创建 /// <summary> /// 通过Xml方式创建 /// </summary> public void CreateByXML() { if (object.Equals(ChartXML, null)) { return; } XElement xeNode; IEnumerable<XElement> xeSetters; #region Chart.Style try { mySet(ChartXML.Element("Chart.Style").Elements("Setter"), this._Chart, typeof(Chart)); } catch { } #endregion #region Chart.BorderSkin try { mySet(ChartXML.Element("Chart.BorderSkin").Elements("Setter"), this._Chart.BorderSkin, typeof(BorderSkin)); } catch { } #endregion #region Chart.Title xeNode = ChartXML.Element("Chart.Title"); if (xeNode.Attribute("Enabled").Value.ToString().ToLower() == "true") { //定义要赋值的对象 Title myTitle = new Title(); mySet(xeNode.Elements("Setter"), myTitle, typeof(Title)); myTitle.Font = FontSet(xeNode.Element("Font").Elements("Setter")); this._Chart.Titles.Add(myTitle); } #endregion #region Chart.ChartAreas int n = 0; int m = ChartXML.Element("Chart.ChartArea").Elements("ChartArea").Count<XElement>(); foreach (XElement elArea in ChartXML.Element("Chart.ChartArea").Elements("ChartArea")) { //定义一个区域 ChartArea ca = new ChartArea(); #region ChartAreas.Attribute //区域属性 mySet(elArea.Element("CahwtArea.Attribute").Elements("Setter"), ca, typeof(ChartArea)); #endregion #region ChartArea.Position try { //区域位置 mySet(elArea.Element("ChartArea.Position").Elements("Setter"), ca.Position, typeof(ElementPosition)); } catch { ca.Position = new ElementPosition(4, 4 + n * 92 / m, 92, 92 / m); n++; } #endregion #region ChartArea.Axis foreach (XElement elAxis in elArea.Element("ChartArea.Axis").Elements("Axis")) { Axis ax; switch (elAxis.Attribute("Name").Value.ToString().ToLower()) { case "axisx": ax = ca.AxisX; break; case "axisx2": ax = ca.AxisX2; break; case "axisy": ax = ca.AxisY; break; case "axisy2": ax = ca.AxisY2; break; default: ax = null; break; } if (elAxis.Attribute("Enabled").Value.ToString().ToLower() == "false") { ax.Enabled = AxisEnabled.False; continue; } else { ax.Enabled = AxisEnabled.True; } #region Axis.Attribute //坐标轴属性 mySetIsTime(elAxis.Element("Axis.Attribute").Elements("Setter"), ax, typeof(Axis)); #endregion #region Axis.Title xeNode = elAxis.Element("Axis.Title"); if (xeNode.Attribute("Enabled").Value.ToString().ToLower() == "true") { //坐标轴文字 mySet(xeNode.Elements("Setter"), ax, typeof(Axis)); //坐标轴文字 ax.TitleFont = FontSet(xeNode.Element("TitleFont").Elements("Setter")); } #endregion #region Axis.Grid xeNode = elAxis.Element("Axis.Grid"); foreach (XElement xeGrid in xeNode.Elements("Grid")) { Grid gr; if (xeGrid.Attribute("Name").Value.ToString().ToLower() == "majorgrid") { gr = ax.MajorGrid; } else { gr = ax.MinorGrid; } if (xeGrid.Attribute("Enabled").Value.ToString().ToLower() == "false") { gr.Enabled = false; continue; } else { gr.Enabled = true; mySet(xeGrid.Elements("Setter"), gr, typeof(Grid)); } } #endregion #region Axis.Title xeNode = elAxis.Element("Axis.LabelStyle"); if (xeNode.Attribute("Enabled").Value.ToString().ToLower() == "true") { //标签属性 mySet(xeNode.Elements("Setter"), ax.LabelStyle, typeof(LabelStyle)); //标签 ax.LabelStyle.Font = FontSet(xeNode.Element("Font").Elements("Setter")); } else { ax.LabelStyle.Enabled = false; } #endregion #region Axis.TickMark xeNode = elAxis.Element("Axis.TickMark"); foreach (XElement xeTickMark in xeNode.Elements("TickMark")) { TickMark tm; if (xeTickMark.Attribute("Name").Value.ToString().ToLower() == "majortickmark") { tm = ax.MajorTickMark; } else { tm = ax.MinorTickMark; } if (xeTickMark.Attribute("Enabled").Value.ToString().ToLower() == "false") { tm.Enabled = false; continue; } else { tm.Enabled = true; mySet(xeTickMark.Elements("Setter"), tm, typeof(TickMark)); } } #endregion #region Axis.ScaleView try { //标签属性 mySet(elAxis.Element("Axis.ScaleView").Elements("Setter"), ax.ScaleView, typeof(AxisScaleView)); } catch { } #endregion } #endregion #region ChartArea.Area3DStyle xeNode = elArea.Element("ChartArea.Area3DStyle"); if (xeNode.Attribute("Enabled").Value.ToString().ToLower() == "true") { ca.Area3DStyle.Enable3D = true; //3d效果 mySet(xeNode.Elements("Setter"), ca.Area3DStyle, typeof(ChartArea3DStyle)); } else { ca.Area3DStyle.Enable3D = false; } #endregion #region ChartArea.Cursor try { foreach (XElement elCursor in elArea.Element("ChartArea.Cursor").Elements("Cursor")) { System.Windows.Forms.DataVisualization.Charting.Cursor cu; if (elCursor.Attribute("Name").Value.ToLower() == "cursorx") { cu = ca.CursorX; } else { cu = ca.CursorY; } mySet(elCursor.Elements("Setter"), cu, typeof(System.Windows.Forms.DataVisualization.Charting.Cursor)); } } catch { } #endregion this._Chart.ChartAreas.Add(ca); } #endregion #region Chart.Series if (ChartXML.Element("Chart.ChartArea").Element("ChartArea") != null) { foreach (XElement elSeries in ChartXML.Element("Chart.Series").Elements("Series")) { Series se = new Series(); se["EmptyPointValue"] = "Average"; se.EmptyPointStyle.BorderWidth = 0; se.EmptyPointStyle.MarkerStyle = MarkerStyle.None; #region Series.Attribute //区域属性 mySet(elSeries.Element("Series.Attribute").Elements("Setter"), se, typeof(Series)); #endregion #region Series.Custom foreach (XElement xeCustom in elSeries.Element("Series.Custom").Elements("Setter")) { se[xeCustom.Attribute("Property").Value.ToString()] = xeCustom.Attribute("Value").Value.ToString(); } #endregion if (elSeries.Element("Series.Marker").Attribute("Enabled").Value.ToString().ToLower() == "true") { #region Series.Attribute //区域属性 mySet(elSeries.Element("Series.Marker").Elements("Setter"), se, typeof(Series)); #endregion } #region Series.Dalta XElement xeDalta = elSeries.Element("Series.Dalta"); if (xeDalta != null) { if (xeDalta.Attribute("Enabled").Value.ToLower() == "true") { Dalta dl = new Dalta(); dl.SerieName = se.Name; mySet(xeDalta.Elements("Setter"), dl, typeof(Dalta)); this.Daltas.Add(dl); } } #endregion this._Chart.Series.Add(se); } } #endregion #region Chart.ToopTip //提示信息样式 mySet(ChartXML.Element("Chart.ToopTip").Elements("Setter"), tipInfo, typeof(TipInfo)); #endregion #region Chart.Custom #region Lines if (ChartXML.Element("Chart.ChartArea").Element("ChartArea") != null) { xeNode = ChartXML.Element("Chart.Custom").Element("Lines"); foreach (XElement xeLine in xeNode.Elements("Line")) { IEnumerable<XElement> LineDirect = from el in xeLine.Elements("Setter") where (string)el.Attribute("Property") == "Direct" select el; if (xeLine.Attribute("Enabled").Value.ToString().ToLower() == "true") { //横线 if (LineDirect.First<XElement>().Attribute("Value").Value.ToString().ToLower() == "h") { HlineInfo myInfo = new HlineInfo(); //横线属性 mySet(xeLine.Elements("Setter"), myInfo, typeof(HlineInfo)); this.InsertHlineInfo.Add(myInfo); } else //竖线 { //找出相对坐标的属性 xeSetters = from el in xeLine.Elements("Setter") where (string)el.Attribute("Property").Value == "IsAb" && el.Attribute("Value").Value.ToString().ToLower() == "false" select el; //没有相对坐标即为绝对坐标 if (xeSetters.Count<XElement>() == 0) { VlineInfo myInfo = new VlineInfo(); //横线属性 mySet(xeLine.Elements("Setter"), myInfo, typeof(VlineInfo)); this.InsertVlineInfo.Add(myInfo); } else//相对坐标 { bool IsTime = false; #region 判断是否为时间轴 xeSetters = from el in xeLine.Elements("Setter") where (string)el.Attribute("Property").Value == "areaName" select el; if (xeSetters != null) { try { foreach (Series s in this._Chart.Series) { if (s.ChartArea == xeSetters.First<XElement>().Attribute("Value").Value.ToString() && s.XValueType == ChartValueType.DateTime) { IsTime = true; break; } } } catch { } } #endregion VlineInfo myInfo = new VlineInfo(); #region 设置除X属性外的其他属性 xeSetters = from el in xeLine.Elements("Setter") where (string)el.Attribute("Property").Value != "X" select el; //横线属性 mySet(xeSetters, myInfo, typeof(VlineInfo)); #endregion #region 设置X属性 xeSetters = from el in xeLine.Elements("Setter") where (string)el.Attribute("Property").Value == "X" select el; if (xeSetters.Count<XElement>() == 0) { continue; } if (IsTime) { myInfo.X = Convert.ToDateTime(xeSetters.First<XElement>().Attribute("Value").Value.ToString()).ToOADate(); } else { try { myInfo.X = Convert.ToDouble(xeSetters.First<XElement>().Attribute("Value").Value.ToString()); } catch { continue; } } #endregion this.InsertVlineInfo.Add(myInfo); } } } } } #endregion #region Images if (ChartXML.Element("Chart.ChartArea").Element("ChartArea") != null) { xeNode = ChartXML.Element("Chart.Custom").Element("Images"); foreach (XElement xeImage in xeNode.Elements("Image")) { if (xeImage.Attribute("Enabled").Value.ToString().ToLower() == "true") { //找出相对坐标的属性 xeSetters = from el in xeImage.Elements("Setter") where (string)el.Attribute("Property").Value == "IsAb" && el.Attribute("Value").Value.ToString().ToLower() == "false" select el; //没有相对坐标即为绝对坐标 if (xeSetters.Count<XElement>() == 0) { ImageInfo myInfo = new ImageInfo(); //横线属性 mySet(xeImage.Elements("Setter"), myInfo, typeof(ImageInfo)); this.InsertImageInfo.Add(myInfo); } else//相对坐标 { ImageInfo myInfo = new ImageInfo(); bool IsTime = false; #region 判断是否为时间轴 xeSetters = from el in xeImage.Elements("Setter") where (string)el.Attribute("Property").Value == "name" select el; if (xeSetters != null) { try { foreach (Series s in this._Chart.Series) { if (s.ChartArea == xeSetters.First<XElement>().Attribute("Value").Value.ToString() && s.XValueType == ChartValueType.DateTime) { IsTime = true; break; } } } catch { } } else { continue; } #endregion #region 设置除X属性外的其他属性 xeSetters = from el in xeImage.Elements("Setter") where (string)el.Attribute("Property").Value != "X" select el; //横线属性 mySet(xeSetters, myInfo, typeof(ImageInfo)); #endregion #region 设置X属性 xeSetters = from el in xeImage.Elements("Setter") where (string)el.Attribute("Property").Value == "X" select el; if (xeSetters.Count<XElement>() == 0) { continue; } if (IsTime) { myInfo.X = Convert.ToDateTime(xeSetters.First<XElement>().Attribute("Value").Value.ToString()).ToOADate(); } else { try { myInfo.X = Convert.ToDouble(xeSetters.First<XElement>().Attribute("Value").Value.ToString()); } catch { continue; } } #endregion this.InsertImageInfo.Add(myInfo); } } } } #endregion #region Letter xeNode = ChartXML.Element("Chart.Custom").Element("Letters"); try { foreach (XElement elLetter in xeNode.Elements("Letter")) { foreach (XElement elString in elLetter.Elements("String")) { LetterInfo li = new LetterInfo(); li.Docking = elLetter.Attribute("Docking").Value; mySet(elString.Elements("Setter"), li, typeof(LetterInfo)); LetterList.Add(li); } } } catch { } #endregion #region Characters xeNode = ChartXML.Element("Chart.Custom").Element("Characters"); try { foreach (XElement elCharacter in xeNode.Elements("Character")) { if (elCharacter.Attribute("Enabled").Value.ToString().ToLower() == "false") { continue; } FontInfo fi = new FontInfo(); mySet(elCharacter.Elements("Setter"), fi, typeof(FontInfo)); fi.IsAb = false; InsertFontInfo.Add(fi); } } catch { } #endregion #region MultiColorsBars InsertColorsBarInfo.Clear(); xeNode = ChartXML.Element("Chart.Custom").Element("MultiColorsBars"); //如果存在多彩指示条信息 if (xeNode != null && xeNode.Elements("Bar") != null) { //循环多彩指示条 foreach (XElement Bar in xeNode.Elements("Bar")) { //创建多彩指示条对象 ColorsBarInfo cbi = new ColorsBarInfo(); //设置多彩指示条属性 mySet(Bar.Elements("Setter"), cbi, typeof(ColorsBarInfo)); // if (Bar.Element("Datas").Elements("Data") != null) { int num = Bar.Element("Datas").Elements("Data").Count<XElement>(); double[] minArray = new double[num]; double[] maxArray = new double[num]; List<Color> colorArray = new List<Color>(); int i = 0; foreach (XElement Data in Bar.Element("Datas").Elements("Data")) { foreach (XElement xSet in Data.Elements("Setter")) { if (xSet.Attribute("Property").Value == "Start") { minArray[i] = double.Parse(xSet.Attribute("Value").Value.ToString()); } else if (xSet.Attribute("Property").Value == "End") { maxArray[i] = double.Parse(xSet.Attribute("Value").Value.ToString()); } else { colorArray.Add(FamtStringColor(xSet.Attribute("Value").Value.ToString())); } } i++; } cbi.minArray = minArray; cbi.maxArray = maxArray; cbi.colorArray = colorArray; } InsertColorsBarInfo.Add(cbi); } } #endregion #region SeriesColors InsertSeriesColorInfo.Clear(); xeNode = ChartXML.Element("Chart.Custom").Element("SeriesColors"); //如果存在多彩指示条信息 if (xeNode != null && xeNode.Elements("Color") != null) { //循环多彩指示条 foreach (XElement color in xeNode.Elements("Color")) { //创建多彩指示条对象 SeriesColorInfo sci = new SeriesColorInfo(); //设置多彩指示条属性 mySet(color.Elements("Setter"), sci, typeof(SeriesColorInfo)); // if (color.Element("Datas").Elements("Data") != null) { int num = color.Element("Datas").Elements("Data").Count<XElement>(); double[] minArray = new double[num]; double[] maxArray = new double[num]; List<PointColor> colorArray = new List<PointColor>(); int i = 0; foreach (XElement Data in color.Element("Datas").Elements("Data")) { PointColor pc = new PointColor(); foreach (XElement xSet in Data.Elements("Setter")) { if (xSet.Attribute("Property").Value == "Start") { minArray[i] = double.Parse(xSet.Attribute("Value").Value.ToString()); } else if (xSet.Attribute("Property").Value == "End") { maxArray[i] = double.Parse(xSet.Attribute("Value").Value.ToString()); } else if (xSet.Attribute("Property").Value == "Color") { pc.Color = FamtStringColor(xSet.Attribute("Value").Value.ToString()); pc.SecondColor = FamtStringColor(xSet.Attribute("Value").Value.ToString()); pc.BorderColor = FamtStringColor(xSet.Attribute("Value").Value.ToString()); } else if (xSet.Attribute("Property").Value == "BorderColor") { pc.BorderColor = FamtStringColor(xSet.Attribute("Value").Value.ToString()); } else if (xSet.Attribute("Property").Value == "BackSecondaryColor") { pc.SecondColor = FamtStringColor(xSet.Attribute("Value").Value.ToString()); } } colorArray.Add(pc); i++; } sci.minArray = minArray; sci.maxArray = maxArray; sci.colorArray = colorArray; } InsertSeriesColorInfo.Add(sci); } } #endregion #endregion } #endregion
我们可以根据自定义的xml开发一个配置界面更改属性,xml用树控件组织节点,点击节点后读取属性节点动态创建输入框、下拉框。
代码如下(牵扯到太多业务)
View Code
#region tree节点选中事件 /// <summary> /// tree节点选中事件 /// *********************************************************** /// 1、找到对应ChartXml中的路径对应的节点 /// 2、找出节点需要修改的属性及下级属性节点 /// 3、循环创建StackPanel,节点属性与节点下属性节点的控件以name区分 /// 4、控件类型依据note属性值 /// ************************************************************ /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void treeView_SelectedItemchanged(object sender, RoutedPropertyChangedEventArgs<object> e) { //清空属性控件 Sp_Attribute.Children.Clear(); #region 查找所选路径 selectPath = ""; XmlElement xe = treeView.SelectedItem as XmlElement; try { GetParent(xe, ref selectPath); } catch { return; } #endregion StackPanel sp = null; //true false选择 Hashtable htTf = new Hashtable(); htTf.Add("True", "True"); htTf.Add("False", "False"); #region 节点属性 #region 是否启用 XmlNode xn = ChartXml.SelectSingleNode(selectPath); if (!object.Equals(xn.Attributes["Enabled"], null)) { sp = new StackPanel(); sp.Orientation = System.Windows.Controls.Orientation.Horizontal; sp.Height = 40; sp.Children.Add(CreateLabel("是否启用", 350, 30)); sp.Children.Add(CreateLabel("", 20, 30)); sp.Children.Add(CreateComboBox("Co_Property", "Co_Attribute", "Enabled", htTf, xn.Attributes["Enabled"].Value)); Sp_Attribute.Children.Add(sp); } #endregion #region 其他属性 //if (!object.Equals(xn.Attributes["Direct"], null)) //{ // Hashtable htd = new Hashtable(); // htd.Add("横线", "h"); // htd.Add("竖线", "v"); // sp = new StackPanel(); // sp.Orientation = Orientation.Horizontal; // sp.Height = 40; // sp.Children.Add(CreateLabel("线方向", 350, 30)); // sp.Children.Add(CreateLabel("", 20, 30)); // sp.Children.Add(CreateComboBox("Co_Property", "Co_Attribute", "Direct", htd, xn.Attributes["Direct"].Value)); // Sp_Attribute.Children.Add(sp); //} #region 可以删除的子项Note属性可以修改 if (!object.Equals(xn.Attributes["Menu"], null) && xn.Attributes["Menu"].Value == "Delete") { sp = new StackPanel(); sp.Orientation = System.Windows.Controls.Orientation.Horizontal; sp.Height = 40; sp.Children.Add(CreateLabel("标示名称", 350, 30)); sp.Children.Add(CreateLabel("", 20, 30)); try { sp.Children.Add(CreateText("Co_Property", "Co_Attribute", "Note", xn.Attributes["Note"].Value)); } catch { } Sp_Attribute.Children.Add(sp); } #endregion #endregion #endregion #region 节点下属性(Setter) XmlNodeList xnl = ChartXml.SelectNodes(selectPath + "/Setter"); for (int i = 0; i < xnl.Count; i++) { string property = xnl[i].Attributes["Property"].Value; string value = xnl[i].Attributes["Value"].Value; string note = xnl[i].Attributes["Note"].Value; sp = new StackPanel(); sp.Orientation = System.Windows.Controls.Orientation.Horizontal; sp.Height = 40; sp.Children.Add(CreateLabel(note.Split('[')[0], 350, 30)); sp.Children.Add(CreateLabel("", 20, 30)); if (note.IndexOf(";") == -1)//没有选项的 { if (value.ToLower() == "true" || value.ToLower() == "false")//值为true 或 false 创建下拉框 { sp.Children.Add(CreateComboBox("Co_Property", "Co_Property", property, htTf, value.ToLower() == "true" ? "True" : "False")); } else//创建输入框 { if (note.IndexOf("颜色") == -1) { if (note.Trim() == "字体") { Hashtable htFf = new Hashtable(); System.Drawing.Text.InstalledFontCollection fonts = new System.Drawing.Text.InstalledFontCollection(); foreach (System.Drawing.FontFamily family in fonts.Families) { htFf.Add(family.Name, family.Name); } sp.Children.Add(CreateComboBox("Co_Property", "Co_Property", property, htFf, value)); } else { sp.Children.Add(CreateText("Co_Property", "Co_Property", property, value)); } } else { System.Windows.Controls.TextBox tb = CreateText("Co_Property", "Co_Property", property, value); sp.Children.Add(tb); System.Windows.Controls.Button bt = CreateButton("...", 40, 25); bt.Tag = tb; bt.Click += new RoutedEventHandler(btColor_Click); sp.Children.Add(bt); } } } else//有选项的创建下拉框 { #region 拆分选项 string[] items = note.Split('[')[1].Split(']')[0].Split(';'); Hashtable ht = new Hashtable(); foreach (string st in items) { string[] nv = st.Split(':'); if (nv.Length == 1) { ht.Add(nv[0], nv[0]); } else { ht.Add(nv[1], nv[0]); } } #endregion if (xnl[i].Attributes["Edited"] == null) { sp.Children.Add(CreateComboBox("Co_Property", "Co_Property", property, ht, value)); } else { sp.Children.Add(CreateComboBox("Co_Property", "Co_PropertyEdit", property, ht, value)); } } Sp_Attribute.Children.Add(sp); } #endregion } #endregion
chart效果图
设置界面示意图: