依存関係プロパティを作成すると、それらのほとんどがUserControlのプロパティの名前(背景、幅など)と競合することがわかりました。そのため、私の戦略では、すべてのカスタムプロパティの前に「The」を付けます。
- 背景
- 幅
等
警告を取り除く「new」キーワードを使用してみましたが、実行時に競合が発生します。
カスタムユーザーコントロールの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
}