我想创建一个样式来修改我的所有窗口并添加一些控件.我的窗口看起来像这样:我想让它看起来像这样:通过应用样式,我不必在所有窗口中复制代码.我怎样才能做到这一点?解决方法:1.是一个资源字典ResourceDiction...
我想创建一个样式来修改我的所有窗口并添加一些控件.
我的窗口看起来像这样:
我想让它看起来像这样:
通过应用样式,我不必在所有窗口中复制代码.
我怎样才能做到这一点?
解决方法:
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.resource和设置样式
<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>
沃梦达教程
本文标题为:c# – 如何在我的所有Windows上添加通用控件?
猜你喜欢
- c# 模拟线性回归的示例 2023-03-14
- Unity Shader实现模糊效果 2023-04-27
- .NET CORE DI 依赖注入 2023-09-27
- C# 使用Aspose.Cells 导出Excel的步骤及问题记录 2023-05-16
- user32.dll 函数说明小结 2022-12-26
- Oracle中for循环的使用方法 2023-07-04
- Unity3D实现渐变颜色效果 2023-01-16
- 在C# 8中如何使用默认接口方法详解 2023-03-29
- WPF使用DrawingContext实现绘制刻度条 2023-07-04
- 如何使用C# 捕获进程输出 2023-03-10