我有我的UserControl
<UserControl x:Class="CustomCtrl.MyButton">
<Button x:Name="Btn" />
</UserControl>
我用我UserControl
的Window
<Window>
<Grid>
<MyButton Background="Aqua" />
</Grid>
</Window>
我想使用带有 XAML的 my的属性来更改Background
ButtonBtn
的属性。Background
UserControl
我尝试添加Background
属性
public class MyButton: UserControl
{
public new Brush Background
{
get
{ return Btn.GetValue(BackgroundProperty) as Brush; }
set
{ Btn.SetValue(BackgroundProperty, value); }
}
}
但它没有效果。
相反,如果我使用代码MyButtonControl.Background = Brushes.Aqua;
,它可以工作。
为什么?我该如何解决这个问题?