私は、アプリケーションの各ウィンドウが一番上に同じメニュー、下に著作権、全体的なルック・アンド・フィール(色など)を共有するように、ウィンドウコントロールテンプレートを作成しました。新しいウィンドウを作成してテンプレートを適用すると、新しいウィンドウはテンプレートのように見えますが、新しいウィンドウは追加できません。新しいウィンドウにドラッグするものはすべて表示されません(つまり、XAMLには追加したコントロールが表示されますが、ウィンドウには表示されません)。テンプレートは行く方法ではありませんか?上で述べたように、私は各ウィンドウに同じメニューを使用させ、同じレイアウト(色、著作権のテキストボックスを下に)を持たせようとしています。それ以外は、それぞれの特定のウィンドウに関連する他のアイテムを「テンプレート化」ウィンドウに配置できます。十分に基本的だが、VB 6の人がWPF(と間違いなくWPF好き)を把握しようとすると、これを実装する方法が不足している。どんな助けもありがとうございます。以下は私のテンプレートのコードですし、そのテンプレートを使って新しいウィンドウを設定する方法です。 "適用" テンプレートを使用してWPF Windowsテンプレートに基づいてウィンドウにアイテムを追加するにはどうすればよいですか?
<Style x:Key="WindowTemplateMain" TargetType="{x:Type Window}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<DockPanel Margin="0,0,-1.667,0.333" HorizontalAlignment="Stretch" Width="Auto">
<DockPanel.Background>
<LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
<GradientStop Color="#FFAEC2EE" Offset="0"/>
<GradientStop Color="#FFFEFEFE" Offset="1"/>
</LinearGradientBrush>
</DockPanel.Background>
<Menu DockPanel.Dock="Top">
<MenuItem Header="_File">
<MenuItem Header="_Time Entry" Name="mnu_TimeEntry" Click="mnu_TimeEntry" />
<Separator />
<MenuItem Header="_Logout" Click="mnu_LogoutClick"/>
<Separator />
<MenuItem Header="_Exit" Click="mnu_ExitClick"/>
</MenuItem>
<MenuItem Header="_Reports">
<MenuItem Header="_Report1" />
<MenuItem Header="_Report2" />
<MenuItem Header="_Report3" />
</MenuItem>
<MenuItem Header="_Administration">
<MenuItem Header="_Task1" />
<MenuItem Header="_Task2" />
<MenuItem Header="_Task3" />
</MenuItem>
</Menu>
<Grid Margin="0,0,0,0" Width="Auto">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="74*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="3*"/>
</Grid.RowDefinitions>
<TextBlock Style="{StaticResource MWB_Copyright}" Grid.Row="2" Grid.ColumnSpan="2" Margin="5,0,4.666,4" />
</Grid>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
新しいウィンドウ(Application.Resources中)
テンプレート:
ボタン "にMyButtonは" 私はツールボックスやショーから上にドラッグするものである<Window x:Class="MWB_TimeKeeper_Main"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MWB_TimeKeeper"
mc:Ignorable="d"
Title="MWB TimeKeeper Main"
Style="{DynamicResource WindowTemplateMain}" >
<Button x:Name="MyButton" Content="MyButton" Height="100" Width="75"/>
</Window>
XAMLコードが表示されますが、ウィンドウに表示されません。繰り返しますが、テンプレートを正しく使用していない、またはスタイル/テンプレートの組み合わせを使用する必要があると確信していますが、わかりませんし、しばらくウェブを検索しました。
ありがとうございました!
テンプレートに[のContentPresenter](https://msdn.microsoft.com/en-us/library/system.windows.controls.contentpresenter%28v=vs.110%29.aspx)を追加します。コンテンツが表示される場所を選択します。 –