当前位置: 首页 > news >正文

江西网站开发企业网站设计理念

江西网站开发,企业网站设计理念,中小企业管理软件,先做网站还是先备案目录 前言一、Style1.1 例子1.2 为样式起名字1.3 BasedOn 继承上一个样式 二、外部StyleStep1 创建资源字典BaseButtonStyle.xamlStep2 在资源字典中写入StyleStep3 App.xaml中写引用路径【全局】Step4 调用三、代码提供四、x:Key和x:Name区别 更新时间 前言 参考文章&#xff…

目录

  • 前言
  • 一、Style
    • 1.1 例子
    • 1.2 为样式起名字
    • 1.3 BasedOn 继承上一个样式
  • 二、外部Style
    • Step1 创建资源字典BaseButtonStyle.xaml
    • Step2 在资源字典中写入Style
    • Step3 App.xaml中写引用路径【全局】
    • Step4 调用
    • 三、代码提供
    • 四、x:Key和x:Name区别
  • 更新时间


前言

参考文章:
参考视频:【WPF入门教程 Visual Studio 2022】WPF界面开发入门

自己的感想


一、Style

如下图所示,在Windows.Resources中设置的Style属性,只在当前界面产生效果。
在这里插入图片描述

1.1 例子

在这里插入图片描述

<Window x:Class="WPF_Study.MainWindow"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:WPF_Study"mc:Ignorable="d"Title="WPF入门.txt" Height="600" Width="800"><Window.Resources><Style TargetType="Button"><Setter Property="Background" Value="Red"/><Setter Property="FontSize" Value="20"/><Setter Property="Height" Value="40"/><Setter Property="Width" Value="70"/></Style></Window.Resources><StackPanel><Button Content="登录" /><Button Content="帮助" /><Button Content="退出" /></StackPanel></Window>

1.2 为样式起名字

为啥要起别名?1.1中的案例导致所有的Button组件都是这个红色样式,但是如果我们只想让退出按钮为红色,其他三个按钮为绿色,该怎么操作?
在这里插入图片描述

<Window x:Class="WPF_Study.MainWindow"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:WPF_Study"mc:Ignorable="d"Title="WPF入门.txt" Height="600" Width="800"><Window.Resources><Style x:Key="QuitStyle" TargetType="Button"><Setter Property="Background" Value="Red"/><Setter Property="FontSize" Value="20"/><Setter Property="Height" Value="40"/><Setter Property="Width" Value="70"/></Style><Style x:Key="loginStyle" TargetType="Button"><Setter Property="Background" Value="Green"/><Setter Property="FontSize" Value="20"/><Setter Property="Height" Value="40"/><Setter Property="Width" Value="70"/></Style></Window.Resources><StackPanel><Button Style="{StaticResource loginStyle}" Content="登录" /><Button Style="{StaticResource loginStyle}" Content="帮助" /><Button Style="{StaticResource QuitStyle}" Content="退出" /></StackPanel></Window>

1.3 BasedOn 继承上一个样式

在这里插入图片描述

<Window x:Class="WPF_Study.MainWindow"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:WPF_Study"mc:Ignorable="d"Title="WPF入门.txt" Height="600" Width="800"><Window.Resources><Style TargetType="Button"><Setter Property="Background" Value="WhiteSmoke"/><Setter Property="FontSize" Value="20"/><Setter Property="Margin" Value="20,10"/></Style><Style x:Key="QuitStyle" TargetType="Button" BasedOn="{StaticResource {x:Type Button}}"><Setter Property="Background" Value="Red"/></Style><Style x:Key="loginStyle" TargetType="Button" BasedOn="{StaticResource {x:Type Button}}"><Setter Property="Background" Value="Green"/></Style></Window.Resources><StackPanel><Button Style="{StaticResource loginStyle}" Content="登录" /><Button Content="帮助" /><Button Style="{StaticResource QuitStyle}" Content="退出" /></StackPanel></Window>

二、外部Style

需要我们把style放入xaml文件中。

Step1 创建资源字典BaseButtonStyle.xaml

在这里插入图片描述

Step2 在资源字典中写入Style

在这里插入图片描述

Step3 App.xaml中写引用路径【全局】

在这里插入图片描述

Step4 调用

在这里插入图片描述


三、代码提供

C# WPF中的Style写入xaml中进行全局引用——点击下载代码


四、x:Key和x:Name区别

  • 在Resources中进行唯一标定。

在这里插入图片描述
在这里插入图片描述


更新时间

  • 2025-02-06:创建。
  • 2025-02-07:补充x:key和x:name之间区别。
http://www.yayakq.cn/news/875044/

相关文章:

  • 安装网站模版视频教程腾讯会议新闻
  • 乌兰察布网站制作seo是什么意思中文
  • 搭建网站的流程和方法二手交易网站开发技术路线
  • 如何搭建aspx网站交通局网站模板
  • 网站建设公司怎么运营专业网页制作与网站设计
  • 亦庄网站开发自己制作网页查询系统
  • 安联建设集团股份公司网站招商加盟项目推荐
  • php 实现网站扫码登录个人主页图片素材
  • 想把公司的外部网站替换浅灰色做网站背景
  • 家电网站制作劳务公司网站建设
  • 秦皇岛手机网站制作多少钱网站ui设计收费
  • 四川省建设厅网站为什么打不开网易免费邮箱注册
  • 中国建设工程协会网站安装wordpress报错
  • 沧州网站备案网站优化排名技巧
  • 自适应影视网站模板wordpress如何添加广告代码
  • 下沙网站制作wordpress音乐播放显示歌词
  • 嘉兴简单建站分销系统搭建
  • 做ppt做好的网站烟台做网站谁家好
  • 怎么在网上做装修网站企业官网网页
  • 长沙网站推广系统wordpress 文章数量
  • 利用ionic做的网站网站seo推广的方法
  • 装饰工程有限公司起名大全wordpress速度优化简书
  • 哪些网站可以用gif做头像wordpress mx主题VIP
  • 商洛 网站建设wordpress3.5.1zhcn
  • 网站优化需要工具网页设计与制作怎么把图片加进去
  • 织梦cms做视频网站wordpress站群+优化
  • 微信卖货小程序seo标题关键词怎么写
  • 硬件开发一站式平台阜新市网站建设
  • 网站的建设服务平台wordpress 投资
  • php做的网站好不好国内营销策划咨询公司