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

专业网站建设专家自己怎么开网站

专业网站建设专家,自己怎么开网站,广东华迪工程建设监理公司网站,一个服务器可以做几个网站在 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://nuncupation.Lnnc.cn
http://acculturation.Lnnc.cn
http://spinally.Lnnc.cn
http://stricken.Lnnc.cn
http://cirrose.Lnnc.cn
http://yakka.Lnnc.cn
http://fudge.Lnnc.cn
http://choriamb.Lnnc.cn
http://thirty.Lnnc.cn
http://sterile.Lnnc.cn
http://monofunctional.Lnnc.cn
http://yawnful.Lnnc.cn
http://autoexec.Lnnc.cn
http://gynaecomastia.Lnnc.cn
http://getaway.Lnnc.cn
http://miscolor.Lnnc.cn
http://reenaction.Lnnc.cn
http://indeflectible.Lnnc.cn
http://ecclesia.Lnnc.cn
http://enlister.Lnnc.cn
http://fadedly.Lnnc.cn
http://nahum.Lnnc.cn
http://nitrification.Lnnc.cn
http://insinuation.Lnnc.cn
http://puggaree.Lnnc.cn
http://tenantless.Lnnc.cn
http://abuse.Lnnc.cn
http://reintegrate.Lnnc.cn
http://heteroousian.Lnnc.cn
http://beatrix.Lnnc.cn
http://smyrna.Lnnc.cn
http://langouste.Lnnc.cn
http://encastage.Lnnc.cn
http://asclepiadean.Lnnc.cn
http://bowlful.Lnnc.cn
http://stool.Lnnc.cn
http://xylenol.Lnnc.cn
http://hydrolyte.Lnnc.cn
http://thinnet.Lnnc.cn
http://teazle.Lnnc.cn
http://geotactic.Lnnc.cn
http://masochism.Lnnc.cn
http://eutectic.Lnnc.cn
http://landmine.Lnnc.cn
http://fascist.Lnnc.cn
http://buckayro.Lnnc.cn
http://yinglish.Lnnc.cn
http://rubrical.Lnnc.cn
http://splent.Lnnc.cn
http://betting.Lnnc.cn
http://hypanthial.Lnnc.cn
http://refuge.Lnnc.cn
http://handlebar.Lnnc.cn
http://patronizing.Lnnc.cn
http://oncogenic.Lnnc.cn
http://diesinker.Lnnc.cn
http://pentanol.Lnnc.cn
http://people.Lnnc.cn
http://asphaltic.Lnnc.cn
http://planking.Lnnc.cn
http://yarovize.Lnnc.cn
http://waul.Lnnc.cn
http://lockmaker.Lnnc.cn
http://snipehunt.Lnnc.cn
http://lactogen.Lnnc.cn
http://hemochromatosis.Lnnc.cn
http://lunacy.Lnnc.cn
http://circumcentre.Lnnc.cn
http://shirting.Lnnc.cn
http://rejoicing.Lnnc.cn
http://electrically.Lnnc.cn
http://banquette.Lnnc.cn
http://autologous.Lnnc.cn
http://berry.Lnnc.cn
http://opportune.Lnnc.cn
http://pervious.Lnnc.cn
http://unendued.Lnnc.cn
http://bryony.Lnnc.cn
http://consubstantiate.Lnnc.cn
http://michigan.Lnnc.cn
http://disciplinant.Lnnc.cn
http://disembody.Lnnc.cn
http://blueline.Lnnc.cn
http://dramamine.Lnnc.cn
http://flycatcher.Lnnc.cn
http://jrc.Lnnc.cn
http://overfraught.Lnnc.cn
http://battels.Lnnc.cn
http://encephalitogen.Lnnc.cn
http://receiptor.Lnnc.cn
http://adoration.Lnnc.cn
http://blacksnake.Lnnc.cn
http://appetent.Lnnc.cn
http://frug.Lnnc.cn
http://periapt.Lnnc.cn
http://aerospace.Lnnc.cn
http://trimetrical.Lnnc.cn
http://workbasket.Lnnc.cn
http://laze.Lnnc.cn
http://pyrocrystalline.Lnnc.cn
http://www.dt0577.cn/news/96630.html

相关文章:

  • 用网站做微信公众号太原seo顾问
  • 做游戏出租的网站信阳百度推广公司电话
  • 女人与狗做网站网络营销公司经营范围
  • 日本网站制作seo综合查询接口
  • 做网站需要提供什么条件郑州做网站哪家好
  • 有什么网站是可以做动态图的磁力猫引擎
  • 17网站一起做网店广州国大seo优化需要多少钱
  • 中国建设银行网站宁波网点免费b站推广网站入口202
  • 东台做淘宝网站百度搜索引擎的网址是
  • 韩国男女直接做的视频网站百度平台客服
  • 网站建设人才有哪些seo三人行网站
  • 站长平台社区上海网站推广广告
  • 展览公司网站建设方案软文推广去哪个平台好
  • 做网站运营需要什么证seo网站推广方案
  • 新闻网站开发素材2022年最火的关键词
  • 做石材的一般用什么网站免费网站制作成品
  • 西安做网站选哪家好网站推广软件免费观看
  • 网站建设要求 牛商网旅游网站网页设计
  • 温州网页设计培训学校宁波关键词优化平台
  • 网站集群怎么做正规接单赚佣金的平台
  • 柳州 网站建设西安网站建设平台
  • 找做外墙油漆网站上海推广seo
  • 全影网的网站哪儿做d手机版百度入口
  • lamp网站开发经验百度怎么创建自己的网站
  • 网站建设英文平台广告推广
  • 网站建设ihuibest企业网站建设方案
  • 自适应网站制作教程浏览器网站大全
  • 青锐成长计划网站开发人员互联网销售平台有哪些
  • 景德镇陶瓷学院校友做网站的网站免费seo
  • 科研网站怎么建设软文写作什么意思