Создал контрол:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
using System;
using System.Windows;
using System.Windows.Controls;
namespace Test
{
public class ComplexControl: UserControl
{
static ComplexControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ComplexControl), new FrameworkPropertyMetadata(typeof(ComplexControl)));
}
public object Left
{
get { return Content; }
set { Content = value; }
}
public object Right
{
get { return (object)GetValue(RightProperty); }
set { SetValue(RightProperty, value); }
}
public static readonly DependencyProperty LeftProperty =
DependencyProperty.Register("Left", typeof(object), typeof(ComplexControl), new UIPropertyMetadata(null));
public static readonly DependencyProperty RightProperty =
DependencyProperty.Register("Right", typeof(object), typeof(ComplexControl), new UIPropertyMetadata(null));
}
}
Создал шаблон заполнения этого контрола в файле Generic.xaml:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Test">
<ControlTemplate x:Key="Decorator" TargetType="local:ComplexControl">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<ContentPresenter Grid.Column="0" ContentSource="Left"/>
<ContentPresenter Grid.Column="1" ContentSource="Right"/>
</Grid>
</ControlTemplate>
</ResourceDictionary>
Разместил контрол в главном окне и заполнил его:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
<Window x:Class="Test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Test"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/Generic.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<local:ComplexControl Template="{StaticResource Decorator}">
<local:ComplexControl.Left>
<Button Content="Left"/>
</local:ComplexControl.Left>
<local:ComplexControl.Right>
<Button Content="Right"/>
</local:ComplexControl.Right>
</local:ComplexControl>
</Window>
Все хорошо отображается. Но, в дизайнере, невозможно выбрать мышью контролы <Button/>, и они не отображаются в окне "Document Outline". Кто сталкивался с такой проблемой?