I have a 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; }
}
}
}
And I want to be able to change the Background
property in Blend.
When I define the Background
property as new, changing it in Blend does not affect my button.
When I define it as override i get the error : 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
What is the best way to override UserControl
properties in order to be able to modify them in Blend ?
EDIT:
A workaround that I found is to rename all RoundButton
properties and block the UserControl
properties form being displayed in Blend :
public new Brush _Background
{
get { return _Border.Background; }
set { _Border.Background = value; }
}
[Browsable(false)]
public new Brush Background { get; set; }