我发现,当我使依赖属性,其中大多数冲突与用户控件中的属性名称,例如背景,宽度等,所以我的策略是前缀所有我的自定义属性与“The”所以我有,例如不使DependencyProperties与实际属性冲突的最佳方法是什么?
- 后台运行此程序
- TheWidth
等
我尝试使用它摆脱了警告的 “新” 的关键字,但是这将导致冲突,在运行时。
有没有人在定制用户控件中使用DependencyProperties的更好的命名策略?
public partial class SmartForm : UserControl
{
public SmartForm()
{
InitializeComponent();
DataContext = this;
TheBackground = "#FFD700";
}
#region DependencyProperty: TheBackground
public string TheBackground
{
get
{
return (string)GetValue(TheBackgroundProperty);
}
set
{
SetValue(TheBackgroundProperty, value);
}
}
public static readonly DependencyProperty TheBackgroundProperty =
DependencyProperty.Register("TheBackground", typeof(string), typeof(SmartForm),
new FrameworkPropertyMetadata());
#endregion
}
谢谢,有道理,也适用。 – 2009-05-25 10:03:32