我想创建一个样式来修改我的所有窗口并添加一些控件.我的窗口看起来像这样:我想让它看起来像这样:通过应用样式,我不必在所有窗口中复制代码.我怎样才能做到这一点?解决方法: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-09
- C# 解析XML和反序列化的示例 2023-04-14
- 实例详解C#实现http不同方法的请求 2022-12-26
- C#通过标签软件Bartender的ZPL命令打印条码 2023-05-16
- C#中的Linq to JSON操作详解 2023-06-08
- Unity 如何获取鼠标停留位置下的物体 2023-04-10
- C#获取指定目录下某种格式文件集并备份到指定文件夹 2023-05-30
- Unity shader实现高斯模糊效果 2023-01-16
- c# – USING块在网站与Windows窗体中的行为不同 2023-09-20
- C#中 Json 序列化去掉null值的方法 2022-11-18