There is a button
<UserControl x:Class="WCL1.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" xmlns:local="clr-namespace:WCL1" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> <Grid> <Button Height="{Binding ElementName=RoundButton, Path=Height}" Width="{Binding ElementName=RoundButton, Path=Wight}" VerticalAlignment="Top" HorizontalAlignment="Left"> <Button.Template> <ControlTemplate> <Grid x:Name="controlLayout"> <Ellipse x:Name="buttonSurface" Fill="LightBlue"></Ellipse> <Label x:Name="buttonCaption" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="20" Content="{Binding ElementName=RoundButton, Path=Text}"></Label> </Grid> </ControlTemplate> </Button.Template> </Button> </Grid> </UserControl> public partial class RoundButton : UserControl { static DependencyProperty TextProperty; static DependencyProperty FillProperty; // static DependencyProperty HeightProperty; //static DependencyProperty FontSizeProperty; //static DependencyProperty FillProperty; //static DependencyProperty FillProperty; //static DependencyProperty FillProperty; //static DependencyProperty FillProperty; public RoundButton() { TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(RoundButton),null); FillProperty = DependencyProperty.Register("Fill", typeof(string), typeof(RoundButton), null); InitializeComponent(); } public string Text { get { return (string)GetValue(TextProperty); } set { SetValue(TextProperty, value); } } public Brush Fill { get { return (Brush)GetValue(FillProperty); } set { SetValue(FillProperty, value); } } private static void OnContentChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { RoundButton rb = (RoundButton)sender; } } I connect the library to the project and want to use this button
<myDll:RoundButton Height="30" Width="30"></myDll:RoundButton> But all properties have zero reaction, and the value Fill says that it is not valid, and the text "text property is already registered in RoundButton" and gives an error.
How to make this UserControl as close as possible to a regular Button element?
PS
It was decided to abandon UserControl and use a custom library of controls.
namespace WCCL1 { /// <summary> /// Выполните шаги 1a или 1b, а затем 2, чтобы использовать этот пользовательский элемент управления в файле XAML. /// /// Шаг 1a. Использование пользовательского элемента управления в файле XAML, существующем в текущем проекте. /// Добавьте атрибут XmlNamespace в корневой элемент файла разметки, где он /// будет использоваться: /// /// xmlns:MyNamespace="clr-namespace:WCCL1" /// /// /// Шаг 1б. Использование пользовательского элемента управления в файле XAML, существующем в другом проекте. /// Добавьте атрибут XmlNamespace в корневой элемент файла разметки, где он /// будет использоваться: /// /// xmlns:MyNamespace="clr-namespace:WCCL1;assembly=WCCL1" /// /// Потребуется также добавить ссылку из проекта, в котором находится файл XAML, /// на данный проект и пересобрать во избежание ошибок компиляции: /// /// Щелкните правой кнопкой мыши нужный проект в обозревателе решений и выберите /// "Добавить ссылку"->"Проекты"->[Поиск и выбор проекта] /// /// /// Шаг 2) /// Теперь можно использовать элемент управления в файле XAML. /// /// <MyNamespace:RoundButton/> /// /// </summary> public class RoundButton : Control { string dText = "RounButton"; Brush dFill = Brushes.Blue; public string Text { get { return dText; } set { dText = value; } } public Brush Fill { get { return dFill; } set { dFill = value; } } static RoundButton() { DefaultStyleKeyProperty.OverrideMetadata(typeof(RoundButton), new FrameworkPropertyMetadata(typeof(RoundButton))); } } } <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WCCL1"> <Style TargetType="{x:Type local:RoundButton}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type local:RoundButton}"> <Grid x:Name="controlLayout"> <Ellipse x:Name="buttonSurface" Fill="{Binding Fill}"></Ellipse> <Label x:Name="buttonCaption" VerticalAlignment="Center" HorizontalAlignment="Center" FontWeight="Bold" FontSize="20" Content="{Binding Text}"></Label> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary> How now to connect this library and am I all zabindil?