我有我的UserControl
<UserControl x:Class="CustomCtrl.MyButton">
<Button x:Name="Btn" />
</UserControl>
我用我UserControl的Window
<Window>
<Grid>
<MyButton Background="Aqua" />
</Grid>
</Window>
我想使用带有 XAML的 my的属性来更改BackgroundButtonBtn的属性。BackgroundUserControl
我尝试添加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;,它可以工作。
为什么?我该如何解决这个问题?