最近的项目需要更新自定义控件的属性值至控件的界面中一个Label里显示,查阅了各种实现方法,最后自己的实现如下。
1.class代码
#region used namespace using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; #endregion namespace CPAToolkit { /// <summary> /// MyControl.xaml 的交互逻辑 /// </summary> public partial class MyControl : UserControl { public MyControl() { InitializeComponent(); FileType = "None"; FileName = "None"; } public String FileType { get { return (string)GetValue(propFileType); } set { SetValue(propFileType, value); } } public static readonly DependencyProperty propFileType = DependencyProperty.Register("FileType", typeof(stri