我创建了以下菜单。现在我想在不同的窗口上使用相同的菜单布局,并考虑将下面的代码转移到 Generic.xaml 并只在需要时引用它。最好的方法是什么,以便实际使用尽可能短?
<MenuHeight="27"VerticalAlignment="Top" ItemsSource="{Binding Menu}">
<Menu.ItemContainerStyle>
<Style TargetType="MenuItem">
<Setter Property="Command" Value="{Binding Execute}"/>
<Setter Property="Icon" Value="{Binding Icon}" />
<Setter Property="ToolTip" Value="{Binding ToolTip}"/>
</Style>
</Menu.ItemContainerStyle>
<Menu.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children}" >
<TextBlock Text="{Binding Header}" />
<HierarchicalDataTemplate.ItemContainerStyle>
<Style TargetType="MenuItem">
<Setter Property="Command" Value="{Binding Execute}"/>
<Setter Property="Icon" Value="{Binding Icon}" />
<Setter Property="ToolTip" Value="{Binding ToolTip}"/>
</Style>
</HierarchicalDataTemplate.ItemContainerStyle>
</HierarchicalDataTemplate>
</Menu.ItemTemplate>
</Menu>