Я делал свой собственный элемент управления, и у меня возникли проблемы, когда я хотел, чтобы моя OwnButton реагировала как правильный компонент.Я хотел бы, чтобы содержимое моего компонента было «ownButton», когда его перетаскивали в конструктор, а затем в списке свойств было бы свойство «Content», где программист мог бы изменить этот текст на любое необходимое.
Вот часть моего файла Generic.xaml:
<Button x:Name="PART_Button" Grid.Row="1" Margin="1,1,1,1" Template="{StaticResource OwnButtonTemplate}">
<TextBlock Text="ownButton" FontFamily="Tahoma" FontSize="10" HorizontalAlignment="Center" VerticalAlignment="Center" Name="textBlock" />
</Button>
Мне удалось создать DependencyProperty в классе OwnButton, но он не связан с содержимым Button.Вот код:
private const string defaultContent = "ownButton";
public String Content
{
get { return (String)GetValue(ContentProperty); }
set { SetValue(ContentProperty, value); }
}
public static readonly DependencyProperty ContentProperty =
DependencyProperty.Register("Content", typeof(String), typeof(OwnButton), new FrameworkPropertyMetadata(OwnButton.defaultContent, new PropertyChangedCallback(OwnButton.OnContentChanged), new CoerceValueCallback(OwnButton.CoerceContent)));
Может ли кто-нибудь помочь мне с моей проблемой?