文章目录
一、前言
在XAML中使用自定义控件,并在XAML中并赋初始值。
二、使用步骤
1. cs中设置控件属性
设置OriginLocation,ScaleInterval 属性,可以通过XAML内传初始值
c#
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
public partial class RadarChart : UserControl
{
//原点位置
private static readonly DependencyProperty OriginLocationProperty =
DependencyProperty.Register("OriginLocation", typeof(string), typeof(RadarChart));
//刻度间隔
private static readonly DependencyProperty ScaleIntervalProperty =
DependencyProperty.Register("ScaleInterval",typeof(int),typeof(RadarChart));
public string OriginLocation {
get { return (string)GetValue(OriginLocationProperty); }
set { SetValue(OriginLocationProperty, value); }
}
public int ScaleInterval {
get { return (int)GetValue(ScaleIntervalProperty); }
set { SetValue(ScaleIntervalProperty, value); }
}
}
2. 在引入控件时,Xaml传初始值
<components:RadarChart OriginLocation="upleft" ScaleInterval="10" />