Define a custom DependencyProperty
29-12-2015 14:11:25
C# / WPF
0 Bookmark(s)
289 View(s)
Dependency Properties can be declared on any type inheriting from DependencyObject. In VisualStudio you can type the shortcutpropdp (and then press tab twice) to add a dependency property.
// Dependency Property Declaration
public static readonly DependencyProperty BackgroundProperty =
DependencyProperty.Register("Background", typeof(Brush), typeof(MyControl),
new FrameworkPropertyMetadata(Brushes.Transparent));
// Property Wrapper
public Brush Background
{
get { return (Brush)GetValue(BackgroundProperty); }
set { SetValue(BackgroundProperty, value); }
}