我有UserControl
RoundButton.xaml
:
<UserControl x:Class="app.controls.RoundButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d">
<Grid>
<Border x:Name="_Border" Background="Cyan" CornerRadius="2" >
<Border.Effect>
<DropShadowEffect x:Name="_Shadow" BlurRadius="0" ShadowDepth="1" Direction="270" Color="White"/>
</Border.Effect>
<Button x:Name="_Button" Content="RoundButton" Background="{x:Null}" BorderThickness="0" Padding="10,0,10,0"/>
</Border>
</Grid>
</UserControl>
RoundButton.xaml.cs
:
namespace app.controls
{
public partial class RoundButton : UserControl
{
public RoundButton() { InitializeComponent(); }
[EditorBrowsable(EditorBrowsableState.Always), Browsable(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public new Brush Background
{
get { return _Border.Background; }
set { _Border.Background = value; }
}
}
}
我希望能够在Blend中更改Background
属性。
当我将Background
属性定义为新属性时,在Blend中更改它不会影响我的按钮。
当我将其定义为覆盖时,我得到错误:Error 1 'app.controls.RoundButton.Background.get': cannot override inherited member 'System.Windows.Controls.Control.Background.get' because it is not marked virtual, abstract, or override
覆盖UserControl
属性以便能够在Blend中修改它们的最佳方法是什么?
修改
我找到的解决方法是重命名所有RoundButton
属性并阻止在Blend中显示的UserControl
属性表单:
public new Brush _Background
{
get { return _Border.Background; }
set { _Border.Background = value; }
}
[Browsable(false)]
public new Brush Background { get; set; }