0
我想創建一個自定義依賴項屬性,可用於按鈕內容的位置。請幫助我。如何創建按鈕內容,如依賴項屬性
這是我的依賴屬性 -
public class MyControl:Button
{
public static readonly DependencyProperty MyCustomControlProperty =
DependencyProperty.Register("SourceC", typeof(string), typeof(MyControl), new UIPropertyMetadata("my button"));
public string SourceC
{
get { return (string)GetValue(MyCustomControlProperty); }
set { SetValue(MyCustomControlProperty, value); }
}
這是我XAML-
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyWPF"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="MyWPF.MainWindow"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<local:CustomClass x:Key="MDP"/>
<local:CustomProperty x:Key="CP"/>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<local:MyControl x:Name="btn1" SourceC="abc" Click="MyControl_Click" Width="50" Height="30" RenderTransformOrigin="3.74,4.333" VerticalAlignment="Top" Grid.Row="1" Margin="88.5,67,0,0" HorizontalAlignment="Left" Grid.Column="1" d:LayoutOverrides="Width, Height"/>
</Grid>
我希望看到按鈕內容,如 「ABC」,我怎麼能用依賴項屬性創建按鈕內容?
您可能需要重新翻譯你的問題AMIGO。當它坐下時,我不明白爲什麼你不會只用一個帶有內容的Button仍然哈哈。 –