创建 a 时UserControl,您需要使用 aDependencyProperty创建可绑定属性。Page在其他控件(如 a )中使用 UserControl 时,需要使它们按预期运行。DependencyProperties 定义如下:
public int MyProperty
{
get { return (int)GetValue(MyPropertyProperty); }
set { SetValue(MyPropertyProperty, value); }
}
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MyPropertyProperty =
DependencyProperty.Register("MyProperty", typeof(int), typeof(ownerclass), new PropertyMetadata(0));
propdp使用Visual Studio 中的代码段最容易创建它们。
我建议看看这门 MVA 课程(尤其是第一课)如何创建自定义控件