Özellikler, DependencyProperty.Register (veya özel bir düğme oluşturmadıysanız, DependencyProperty.RegisterAttached) kullanarak C# içinde bildirilmesi gerekir. Burada bir özel düğme sınıf oluşturuyorsanız ilanıdır: Özel bir sınıf oluşturarak, ancak normal Düğmesi ayarlanabilir özelliklere tanımlamak istediğiniz değilseniz
public static readonly DependencyProperty ButtonBorderColourProperty =
DependencyProperty.Register("ButtonBorderColour",
typeof(Color), typeof(MyButton)); // optionally metadata for defaults etc.
public Color ButtonBorderColor
{
get { return (Color)GetValue(ButtonBorderColourProperty); }
set { SetValue(ButtonBorderColourProperty, value); }
}
, kullanım RegisterAttached:
public static class ButtonCustomisation
{
public static readonly DependencyProperty ButtonBorderColourProperty =
DependencyProperty.RegisterAttached("ButtonBorderColour",
typeof(Color), typeof(ButtonCustomisation)); // optionally metadata for defaults etc.
}
Bunlar daha sonra XAML:
<local:MyButton ButtonBorderColour="HotPink" />
<Button local:ButtonCustomisation.ButtonBorderColour="Lime" />