How to assign a property of type Control in XAML – error-Collection of common programming errors
When you write a WPF application, you’d probably want to avoid using x:Reference
, as it’s a feature of XAML 2009 which is only available for loose XAML.
Alternatively, you can use binding and its ElementName
property. But for that to work you’ll need to make TargetControl
a dependency property. Then it will look like this:
C#
public Control TargetControl
{
get { return (Control)this.GetValue(TargetControlProperty); }
set { this.SetValue(TargetControlProperty, value); }
}
public static readonly DependencyProperty TargetControlProperty =
DependencyProperty.Register("TargetControl",
typeof(Control),
typeof(NumericButtonsControl),
new PropertyMetadata(null));
XAML: