このアプリケーションでは、すべてのビューに「基本的な」レイアウトがあります。一般的なコードを再利用するために、BaseControlクラスとそのテンプレートを作成しました。
私が達成したいのは、「BaseControl」から派生したすべてのコントロールに共通のタイトルとフッターバーです。
XAMLの具体的なビュー:
<my:BaseControl x:Class="SampleView"
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"
mc:Ignorable="d"
xmlns:my="clr-namespace:UserInterface" d:DesignWidth="924">
<Grid>
//This elements are not visible - why?
</Grid>
共通基本クラス(XAMLではなくテンプレート)
public class BaseControl : System.Windows.Controls.UserControl{}
レンプレート:
<Style TargetType="{x:Type my:BaseControl}" BasedOn="{StaticResource {x:Type UserControl}}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid>
....snip
<Border Grid.Row="0" Name="SomeCommonUsedBorder">
<ContentPresenter>
//every thing placed between
//<SampleView> and </SampleView> should go here
</ContentPresenter>
....snip
//some other commonly used elements goes here
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
サンプルビューは期待どおりに見えますが、派生したコントロール内に記述したものはすべて表示されません。
ヒントやアイデアをありがとう
マヌエル