8,737
社区成员
发帖
与我相关
我的任务
分享
比如我要做一个曲线图的控件,会有两个Y坐标轴,一个X坐标轴,而每个坐标轴又有刻度,类模型大概是
// 刻度
class Scale {
// 省略属性和方法定义
}
// Y轴
class YAxis {
public Scale[] Scales{ get; set; }
public double MaxValue { get; set; }
public double MinValue { get; set; }
// 省略其它属性和方法定义
}
// X轴
public XAxis {
public Scale[] Scales{ get; set; }
public double MaxValue { get; set; }
public double MinValue { get; set; }
// 省略其它属性和方法定义
}
// 曲线图
class MyChartLine {
public static DependencyProperty ShowRightYAxisProperty = DependencyProperty.Register("ShowRighttYAxis", typeof(bool), typeof(MyChartLine));
public static DependencyProperty LeftYAxisProperty = DependencyProperty.Register("LeftYAxis", typeof(YAxis), typeof(MyChartLine));
public static DependencyProperty RightYAxisProperty = DependencyProperty.Register("RightYAxis", typeof(YAxis), typeof(MyChartLine));
// 简单属性
public bool ShowRightYAxis {
get{
return (bool)GetValue(ShowRightYAxisProperty);
}
set{
SetValue(ShowRightYAxisProperty, value);
}
}
// 对象属性,省略依赖属性的写法
public YAxis LeftYAxis { get; set; }
public YAxis RightYAxis { get; set; }
public XAxis XAxis { get; set; }
// 省略其它属性和方法定义
}
然后,我希望在使用这个控件时,对两个Y轴和X轴,以及控件的属性可以这样写:
<local:MyChartLine ShowRightYAxis="True">
<LeftYAxis MinValue="0" MaxValue="100">
<Scales>
<Scale ...... />
<Scale ...... />
</Scales>
</LeftYAxis>
<RightYAxis MinValue="-100" MaxValue="500">
<Scales>
<Scale ...... />
<Scale ...... />
</Scales>
</rightYAxis>
</local:MyChartLine>
请问应该要怎么做?