Bir WPF kullanıcı denetimi oluşturuyorum, onun gibi bir çok düzenin ayarlandığı bir pencere. Ancak, kullanıcıların kontrollerini yerleştirmesini istediğim birkaç bölüm var. Bunu başarmak için kullanıcı kontrolümde bazı bağımlılık özelliklerini açığa çıkarmam gerektiğine inanıyorum.WPF Kullanıcı denetiminde birden çok İçerik Sunucusu
Çıktı biraz kullanıcı denetimi
public class Class1 : UserControl
{
public ContentControl Content1
{
get { return (ContentControl)GetValue(Content1Property); }
set { SetValue(Content1Property, value); }
}
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty Content1Property =
DependencyProperty.Register("Content1", typeof(ContentControl), typeof(Class1), null);
public ContentControl Content2
{
get { return (ContentControl)GetValue(Content2Property); }
set { SetValue(Content2Property, value); }
}
// Using a DependencyProperty as the backing store for Content2. This enables animation, styling, binding, etc...
public static readonly DependencyProperty Content2Property =
DependencyProperty.Register("Content2", typeof(ContentControl), typeof(Class1), null);
public ContentControl Content3
{
get { return (ContentControl)GetValue(Content3Property); }
set { SetValue(Content3Property, value); }
}
// Using a DependencyProperty as the backing store for Content3. This enables animation, styling, binding, etc...
public static readonly DependencyProperty Content3Property =
DependencyProperty.Register("Content3", typeof(ContentControl), typeof(Class1),null);
}
için bu
Kanunu Ve kontrolün ilgili xaml gibi olmalıdır
<Style TargetType="{x:Type userControl:Class1}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="userControl:Class1">
<Grid ShowGridLines="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="10"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="10"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="10"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="10"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="10"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="10"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Grid.Row="1" Grid.Column="1" Text="First Content"></TextBlock>
<ContentPresenter x:Name="firstContentPresenter" ContentSource="{TemplateBinding Content1}" Grid.Row="1" Grid.Column="3"></ContentPresenter>
<TextBlock Grid.Row="3" Grid.Column="1" Text="First Content"></TextBlock>
<ContentPresenter x:Name="secondContentPresenter" ContentSource="{TemplateBinding Content2}" Grid.Row="3" Grid.Column="3"></ContentPresenter>
<TextBlock Grid.Row="5" Grid.Column="1" Text="First Content"></TextBlock>
<ContentPresenter x:Name="thirdContentPresenter" ContentSource="{TemplateBinding Content3}" Grid.Row="5" Grid.Column="3"></ContentPresenter>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Ve ben çalışıyorum Bunu birazgibi kullanın Yukarıdaki kodun çıktısı hiçbir şey değildir.
Mayın kodlarını tamamen kendimle değiştirdim. Artık ızgara oluşturmayı bile durdurdu. Lütfen window.xaml için de kodu ekleyin, o zaman işe yarayabilir. – MegaMind
@MegaMind - güncellendi. –
O şeyi özlediğime inanmıyorum. Her neyse yardım için çok teşekkürler. – MegaMind