C# 如何在我的所有窗口上添加公共控件?
我想创建一个样式来修改我的所有窗口,并向其中添加一些控件 我的窗口如下所示: 我想让它看起来像这样: 通过应用样式,我不必在所有窗口中重复代码C# 如何在我的所有窗口上添加公共控件?,c#,wpf,C#,Wpf,我想创建一个样式来修改我的所有窗口,并向其中添加一些控件 我的窗口如下所示: 我想让它看起来像这样: 通过应用样式,我不必在所有窗口中重复代码 我该怎么做呢?1.创建资源字典 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xa
我该怎么做呢?1.创建资源字典
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="winStyle" TargetType="{x:Type Window}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<DockPanel Background="{TemplateBinding Background}">
<Grid Height="200" DockPanel.Dock="Top"/>
<Grid>
<Label Foreground="Black" Content="notifications container"/>
</Grid>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
2.将字典添加到每个窗口。资源和设置样式
<Window x:Class="WpfApplication21.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" Style="{DynamicResource winStyle}">
<Window.Resources>
<ResourceDictionary Source="Dictionary1.xaml" />
</Window.Resources>
</Window>
这近乎完美,我只需要保留窗口内容即可。我想我可以使用ContentPresenter
?这是正确的@BrunoLM,您可能可以尝试使用
。