我有自己的用户控件,其中包括几个按钮等。
我使用此代码将该UC带到屏幕上。
<AppUI:XXXX x:Name="ucStaticBtns" HorizontalAlignment="Left" Margin="484,0,0,0" VerticalAlignment="Top" Width="68" />
我给XXXX用户控件添加了两个属性,比如Property1和Property2。然后修改了我的代码:
<AppUI:XXXX x:Name="ucStaticBtns" HorizontalAlignment="Left" Margin="484,0,0,0" VerticalAlignment="Top" Width="68" Property1="False" Property2="False"/>
当我将这两个参数添加到XAML页面中时,系统会抛出异常,如"The member 'Property1' is not recognized or is not accessible"
这是我的UC代码。
public partial class XXXX : UserControl
{
public event EventHandler CloseClicked;
public event EventHandler MinimizeClicked;
//public bool ShowMinimize { get; set; }
public static DependencyProperty Property1Property;
public static DependencyProperty Property2Property;
public XXXX()
{
InitializeComponent();
}
static XXXX()
{
Property1Property = DependencyProperty.Register("Property1", typeof(bool), typeof(XXXX));
Property2Property = DependencyProperty.Register("Property2", typeof(bool), typeof(XXXX));
}
public bool Property1
{
get { return (bool)base.GetValue(Property1Property); }
set { base.SetValue(Property1Property, value); }
}
public bool Property2
{
get { return (bool)base.GetValue(Property2Property); }
set { base.SetValue(Property2Property, value); }
}
}
你能帮我完成这个吗?非常感谢!