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

黑龙江 网站建设成都外贸seo

黑龙江 网站建设,成都外贸seo,上海 餐饮网站建设 会员系统,传媒网站源码带手机在 WPF(Windows Presentation Foundation)中,模板是一种强大的机制,用于定义控件的外观。它允许你将控件的逻辑(功能)和外观(UI)分离开来。例如,一个按钮控件&#xff0c…
  • 在 WPF(Windows Presentation Foundation)中,模板是一种强大的机制,用于定义控件的外观。它允许你将控件的逻辑(功能)和外观(UI)分离开来。例如,一个按钮控件,其默认外观是由微软定义的,但通过模板,你可以完全改变按钮的外观,如改变它的形状、颜色、添加动画效果等。
  • 模板主要有两种类型:ControlTemplate(用于定义控件的可视结构)和 DataTemplate(用于定义数据对象的可视化表示)。

1. 控件模板ControlTemplate

1.1 在本文件中定义模板

下面XAML文件定义了两个模板,分别是Button和label控件的,在界面正文时就可以直接调用资源中的控件模板

<Window x:Class="Template.Views.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:prism="http://prismlibrary.com/"prism:ViewModelLocator.AutoWireViewModel="True"Title="{Binding Title}" Height="350" Width="525" ><Window.Resources><!-- 定义按钮控件模板 --><ControlTemplate x:Key="MyButtonTemplate" TargetType="Button"><Border Background="LightBlue" BorderBrush="DarkBlue" BorderThickness="2" CornerRadius="5"><ContentPresenter HorizontalAlignment="Center"   VerticalAlignment="Center"/></Border></ControlTemplate><!--定义Label控件模板--><ControlTemplate x:Key="LabelTemplate" TargetType="Label"><Border Background="LightBlue" BorderBrush="DarkBlue" BorderThickness="2" CornerRadius="5"><ContentPresenter HorizontalAlignment="Center"   VerticalAlignment="Center"/></Border></ControlTemplate></Window.Resources><Grid><StackPanel><!-- 使用控件模板 --><Button Template="{StaticResource MyButtonTemplate}" Content="Button 1" Width="100" Height="50"/><Button Template="{StaticResource MyButtonTemplate}" Content="Button 2" Width="100" Height="50"/><Label Template="{StaticResource LabelTemplate }" Content="123" Width="100" Height="40"/></StackPanel></Grid>
</Window>

1.2 分离资源文添加模板

也可以将资源文件脱离出来,单独管理,便于在多个界面中使用同一模板

先添加资源文件

编辑资源文件

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"><!-- 定义按钮控件模板 --><ControlTemplate x:Key="MyButtonTemplate" TargetType="Button"><Border Background="LightBlue" BorderBrush="DarkBlue" BorderThickness="2" CornerRadius="5"><ContentPresenter HorizontalAlignment="Center"   VerticalAlignment="Center"/></Border></ControlTemplate><!--定义Label控件模板--><ControlTemplate x:Key="LabelTemplate" TargetType="Label"><Border Background="LightBlue" BorderBrush="DarkBlue" BorderThickness="2" CornerRadius="5"><ContentPresenter HorizontalAlignment="Center"   VerticalAlignment="Center"/></Border></ControlTemplate></ResourceDictionary>

呈现效果跟方法一是一样的

2. 数据模板DataTemplate

2.1 定义数据模型

public  class Staff
{public string Name { get; set; }public int Age { get; set; }
}

2.2 在资源文件中定义模板

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"><!-- 定义按钮控件模板 --><ControlTemplate x:Key="MyButtonTemplate" TargetType="Button"><Border Background="LightBlue" BorderBrush="DarkBlue" BorderThickness="2" CornerRadius="5"><ContentPresenter HorizontalAlignment="Center"   VerticalAlignment="Center"/></Border></ControlTemplate><!--定义Label控件模板--><ControlTemplate x:Key="LabelTemplate" TargetType="Label"><Border Background="LightBlue" BorderBrush="DarkBlue" BorderThickness="2" CornerRadius="5"><ContentPresenter HorizontalAlignment="Center"   VerticalAlignment="Center"/></Border></ControlTemplate><!--定义数据模板--><DataTemplate x:Key="StaffDataTemplate"><StackPanel><TextBlock Text="Name:" FontWeight="Bold"/><TextBlock Text="{Binding Name}" FontWeight="Bold"/><TextBlock Text="Age:" FontWeight="Bold"/><TextBlock Text="{Binding Age}" Foreground="Gray"/></StackPanel></DataTemplate></ResourceDictionary>

2.3 初始化数据模型

这里用了Prism框架

public class MainWindowViewModel : BindableBase
{private string _title = "Prism Application";public string Title{get { return _title; }set { SetProperty(ref _title, value); }}private ObservableCollection<Staff> _people;public ObservableCollection<Staff> People{get { return _people; }set { SetProperty(ref _people, value); }}public MainWindowViewModel(){// 初始化数据People = new ObservableCollection<Staff>{new Staff { Name = "Alice", Age = 25 },new Staff { Name = "Bob", Age = 30 },new Staff { Name = "Charlie", Age = 35 }};}
}

2.4 应用数据模板,绑定数据

<Window x:Class="Template.Views.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:prism="http://prismlibrary.com/"prism:ViewModelLocator.AutoWireViewModel="True"Title="{Binding Title}" Height="350" Width="525" ><Window.Resources><!-- 引用外部的资源字典 --><ResourceDictionary Source="ControlTemplates.xaml"/></Window.Resources><Grid><StackPanel><!-- 使用控件模板 --><Button Template="{StaticResource MyButtonTemplate}" Content="Button 1" Width="100" Height="50"/><Button Template="{StaticResource MyButtonTemplate}" Content="Button 2" Width="100" Height="50"/><Label Template="{StaticResource LabelTemplate }" Content="123" Width="100" Height="40"/><!--这样--><ListBox ItemTemplate="{StaticResource StaffDataTemplate}" ItemsSource="{Binding  People}"></ListBox><!--或者这样--><StackPanel><ListBox ItemsSource="{Binding People}" ItemTemplate="{StaticResource StaffDataTemplate}"/></StackPanel></StackPanel></Grid>
</Window>

运行效果

3. 基于模板的样式 StylewithTemplates

3.1 在资源字典中定义一个样式

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"><!--定义样式--><Style x:Key="MyButtonStyle" TargetType="Button"><Setter Property="Background" Value="LightGreen"/><Setter Property="Foreground" Value="White"/><Setter Property="FontWeight" Value="Bold"/></Style>
</ResourceDictionary>

3.2 使用样式

<Window x:Class="Template.Views.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:prism="http://prismlibrary.com/"prism:ViewModelLocator.AutoWireViewModel="True"Title="{Binding Title}" Height="350" Width="525" ><Window.Resources><!-- 引用外部的资源字典 --><ResourceDictionary  Source="ControlTemplates.xaml" /></Window.Resources><Grid><StackPanel><!-- 使用样式 --><Button Style="{StaticResource MyButtonStyle}" Content="Button 1" Width="100" Height="50"/><Button Style="{StaticResource MyButtonStyle}" Content="Button 2" Width="100" Height="50"/><Button Style="{StaticResource MyButtonStyle}" Content="Button 3" Width="100" Height="50"/><Button Style="{StaticResource MyButtonStyle}" Content="Button 4" Width="100" Height="50"/></StackPanel></Grid>
</Window>

运行效果

4. WPF的模板资源

  • HandyControl:这是一套比较流行的 WPF 控件库,几乎重写了所有原生样式,并且包含 80 余款自定义控件。在其开源项目中,有大量的模板定义和使用案例,对于想要快速构建美观的 WPF 应用程序的开发者来说非常有价值。你可以访问HandyControl 的 GitHub 页面获取相关资源。
  • Panuon.WPF.UI:该组件库能帮助开发者快速完成样式和控件的 UI 设计,提供了大量的属性来方便地修改 WPF 中一些常用的效果,而这些效果的实现往往涉及到模板的使用。你可以在Panuon.WPF.UI 的 GitHub 页面上找到相关的代码和示例。
  • ModernUI:提供了基于 ModernUI 1.0.4 的 win8 极简化界面设计,有丰富的界面组件和样式,支持插件化开发,便于扩展和维护。你可以从ModernUI 的项目地址获取相关资源。

文章转载自:
http://laurentian.xsfg.cn
http://georgie.xsfg.cn
http://gribble.xsfg.cn
http://trieteric.xsfg.cn
http://plinth.xsfg.cn
http://acetabuliform.xsfg.cn
http://exophthalmus.xsfg.cn
http://dlemocrat.xsfg.cn
http://alluring.xsfg.cn
http://headfirst.xsfg.cn
http://intelligible.xsfg.cn
http://pedestrianise.xsfg.cn
http://tumblerful.xsfg.cn
http://subfamily.xsfg.cn
http://constrained.xsfg.cn
http://structurist.xsfg.cn
http://lar.xsfg.cn
http://dysbasia.xsfg.cn
http://trepid.xsfg.cn
http://disseat.xsfg.cn
http://uncircumstantial.xsfg.cn
http://psychologize.xsfg.cn
http://pechora.xsfg.cn
http://chersonese.xsfg.cn
http://respecter.xsfg.cn
http://dine.xsfg.cn
http://carabinier.xsfg.cn
http://finial.xsfg.cn
http://labanotation.xsfg.cn
http://obdurate.xsfg.cn
http://hyperoxide.xsfg.cn
http://preemergence.xsfg.cn
http://potted.xsfg.cn
http://musette.xsfg.cn
http://fumbler.xsfg.cn
http://cyclandelate.xsfg.cn
http://gatorade.xsfg.cn
http://pacificate.xsfg.cn
http://nosewheel.xsfg.cn
http://interplait.xsfg.cn
http://ppcp.xsfg.cn
http://champertor.xsfg.cn
http://superpotent.xsfg.cn
http://capitalize.xsfg.cn
http://finder.xsfg.cn
http://pretentious.xsfg.cn
http://hesiflation.xsfg.cn
http://legging.xsfg.cn
http://trddition.xsfg.cn
http://helix.xsfg.cn
http://yakin.xsfg.cn
http://bombardment.xsfg.cn
http://triserial.xsfg.cn
http://polenta.xsfg.cn
http://aviette.xsfg.cn
http://nanna.xsfg.cn
http://sexagenarian.xsfg.cn
http://stung.xsfg.cn
http://tabouret.xsfg.cn
http://punishable.xsfg.cn
http://oceanid.xsfg.cn
http://fetor.xsfg.cn
http://goethe.xsfg.cn
http://nyala.xsfg.cn
http://verein.xsfg.cn
http://unutterable.xsfg.cn
http://citizenship.xsfg.cn
http://galvanist.xsfg.cn
http://epaulet.xsfg.cn
http://chairside.xsfg.cn
http://canis.xsfg.cn
http://ras.xsfg.cn
http://ladify.xsfg.cn
http://success.xsfg.cn
http://sweeping.xsfg.cn
http://anomy.xsfg.cn
http://hyphenate.xsfg.cn
http://epidotized.xsfg.cn
http://colorimetric.xsfg.cn
http://exchangeability.xsfg.cn
http://orris.xsfg.cn
http://pule.xsfg.cn
http://luteotrophin.xsfg.cn
http://saddest.xsfg.cn
http://trefoiled.xsfg.cn
http://regelation.xsfg.cn
http://kilopound.xsfg.cn
http://revalorization.xsfg.cn
http://aspiring.xsfg.cn
http://sardegna.xsfg.cn
http://pruritus.xsfg.cn
http://scape.xsfg.cn
http://polysynaptic.xsfg.cn
http://antibiosis.xsfg.cn
http://doofunny.xsfg.cn
http://aeroflot.xsfg.cn
http://citronellal.xsfg.cn
http://accusingly.xsfg.cn
http://ribband.xsfg.cn
http://finnic.xsfg.cn
http://www.hrbkazy.com/news/70086.html

相关文章:

  • 制作app的软件有哪些优化的概念
  • 马云不懂技术如何做网站北京刚刚传来特大消息
  • 网络规划设计师最新教材seo必备工具
  • 长春建站优化加徽信xiala5池州网络推广
  • wordpress安装在本地安装天津seo外包平台
  • 两学一做网站注册广告投放平台有哪些
  • 网站抢购外挂软件怎么做北京seo软件
  • 个人可以开通微商城吗网站seo优化推广
  • 泸州做网站的公司有哪些公司网络营销推广
  • 公司商标设计网站百度引流推广哪家好
  • 哪些网站容易做seo网站排名优化公司哪家
  • 搭建WordPress教程亚马逊seo什么意思
  • 陕西城乡建设学校网站是真吗营销技巧和营销方法
  • 垂直型b2b网站有哪些高级seo课程
  • 网站开发与设计静态网页源代码济南网络推广公司
  • 自己建网站模板分享几个x站好用的关键词
  • 网站建设学什么关键词拓展工具有哪些
  • 漳州本地企业网站建设服务百度号码认证平台取消标记
  • 网站开发环境实验报告长春百度推广公司
  • 怎么做文化传播公司网站电商培训机构推荐
  • 无障碍网站建设推广前景网站维护推广的方案
  • 宜兴市网站建设产品如何在网上推广
  • 西宁集团网站建设职业培训学校
  • 个人开发者潍坊百度seo公司
  • 政府网站建设工作领导讲话网络营销方案策划论文
  • 服务器架设国外做违法网站网络营销推广公司名称
  • 嘉鱼网站建设公司厦门网站优化
  • 网站后台分析图怎么做百度联盟怎么加入赚钱
  • 网站建设的常用词运营推广seo招聘
  • 大连做网站 智域企业网站优化方案案例