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

网站建设 赣icp 南昌上海关键词排名软件

网站建设 赣icp 南昌,上海关键词排名软件,自己做的网站怎么绑域名,c 如何做网站.NET多平台应用程序UI(. NET MAUI)的市场吸引力与日俱增,这是微软最新的开发平台,允许开发者使用单个代码库创建跨平台应用程序。尽管很多WPF开发人员还没有跟上 .NET MAUI的潮流,但我们将在这篇文章中为大家展示他的潜…

.NET多平台应用程序UI(. NET MAUI)的市场吸引力与日俱增,这是微软最新的开发平台,允许开发者使用单个代码库创建跨平台应用程序。尽管很多WPF开发人员还没有跟上 .NET MAUI的潮流,但我们将在这篇文章中为大家展示他的潜力,具体来说想描述一下WPF和.NET MAUI之前的共性。

PS:DevExpress WPF拥有120+个控件和库,将帮助您交付满足甚至超出企业需求的高性能业务应用程序。通过DevExpress WPF能创建有着强大互动功能的XAML基础应用程序,这些应用程序专注于当代客户的需求和构建未来新一代支持触摸的解决方案。

DevExpress WPF 最新版下载(Q技术交流:674691612)

项目结构

与Xamarin不同,.NET MAUI解决方案包含针对所有目标平台的单个项目。像WPF一样, .NET MAUI项目包含一个App.xaml文件和主视图,另外可以发现AppShell类被用作根视觉元素:

Resources文件夹包含跨每个平台使用的应用程序资源,开发者可以将特定于平台的资源放在Platforms目录的子文件夹中,以便在应用程序启动时执行相关代码。

XAML和代码隐藏

.NET MAUI页面具有与WPF窗口或用户控件相似的结构,根元素包含命名空间声明和x:Class属性,该属性定义了代码背后的类名:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiFirstApp.MainPage">
<ScrollView>
<!--...-->
</ScrollView>
</ContentPage>

InitializeComponent方法是根据XAML自动生成的:

namespace MauiFirstApp;
public partial class MainPage : ContentPage {
public MainPage() {
InitializeComponent();
}
}

绑定

.NET MAUI绑定使用与WPF绑定相似的上下文,它有类似的模式、相对源、转换器等。.NET MAUI使用了与WPF的DataContext类似的概念,唯一的区别是这个属性叫做BindingContext:

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiFirstApp"
x:Class="MauiFirstApp.MainPage">
<ContentPage.BindingContext>
<local:ViewModel/>
</ContentPage.BindingContext>
<Label Text="{Binding FirstName}"/>
</ContentPage>

布局

.NET MAUI包含与Grid和StackPanel相似的东西,可以帮助开发者根据业务需求安排可视化元素:

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ListView Grid.Column="0"/>
<StackLayout Grid.Column="1" WidthRequest="50">
<Button Text="Print"/>
<Button Text="Export"/>
</StackLayout>
</Grid>

资源

资源字典存储应用程序资源(样式、模板、转换器等),开发者可以使用StaticResource或DynamicResource标记扩展来将这些资源应用到元素上:

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiFirstApp"
x:Class="MauiFirstApp.MainPage">
<ContentPage.Resources>
<Color x:Key="ButtonBackgroundColor">DarkOrange</Color>
<Color x:Key="ButtonForegroundColor">Black</Color>
</ContentPage.Resources><Button Text="Export"
BackgroundColor="{StaticResource ButtonBackgroundColor}"
TextColor="{StaticResource ButtonForegroundColor}"/>
</ContentPage>

模板

在.NET MAUI中,您可以使用 ControlTemplates 和DataTemplates来保持与WPF相同的UI灵活性:

<ListView>
<ListView.ItemTemplate>
<DataTemplate>
<Label Text="{Binding FirstName}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

样式

开发者可以创建显式和隐式样式来将类似的设置应用于多个元素:

<ContentPage.Resources>
<Style TargetType="Button">
<Setter Property="Background" Value="Orange"/>
<Setter Property="TextColor" Value="White"/>
<Setter Property="CornerRadius" Value="4"/>
</Style>
</ContentPage.Resources>
<StackLayout Orientation="Horizontal">
<Button Text="Next"/>
<Button Text="Prev"/>
</StackLayout>

触发器

声明式XAML触发器允许开发者有条件地应用样式:

<ContentPage.Resources>
<Style TargetType="Editor" x:Key="redOnFocusStyle">
<Style.Triggers>
<Trigger TargetType="Editor" Property="IsFocused" Value="True">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</ContentPage.Resources>
<StackLayout VerticalOptions="Start">
<Editor Text="Red on Focus" Style="{StaticResource redOnFocusStyle}"/>
</StackLayout>

可视化树

与WPF非常相似,可视元素的层次结构允许开发者轻松地识别控件的父元素和子元素,Parent属性包含直接可视父属性和Children属性——直接子属性,主要区别在于.NET MAUI没有逻辑树。

MVVM

.NET MAUI使用与WPF相同的MVVM范例,许多MVVM框架(如Prism)都是跨平台的,因此您不太可能注意到许多差异。下面是一个基本的例子,演示了如何在视图模型中将编辑器绑定到属性,将按钮绑定到命令:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiFirstApp"
x:Class="MauiFirstApp.MainPage">
<ContentPage.BindingContext>
<local:ViewModel/>
</ContentPage.BindingContext>
<StackLayout VerticalOptions="Start">
<Editor Text="{Binding FirstName}"/>
<Button Text="Process" Command="{Binding ProcessUserCommand}"/>
</StackLayout>
</ContentPage>
public class ViewModel : INotifyPropertyChanged {
private string name;
public string FirstName {
get { return name; }
set {
name = value;
OnPropertyChanged();
}
}public ICommand ProcessUserCommand { get; }public ViewModel() {
ProcessUserCommand = new Command(ProcessUser);
}void ProcessUser() {
Console.WriteLine(FirstName);
}public event PropertyChangedEventHandler PropertyChanged;public void OnPropertyChanged([CallerMemberName] string name = "") =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}

依赖项属性

.NET MAUI 依赖属性称为可绑定属性,它们使用类似的声明结构:一个静态字段和一个公共属性。BindableProperty.Create方法接受所有与DependencyProperty.Register类似的参数在WPF中注册:

public int MaxValue {
get => (int)GetValue(MaxValueProperty);
set => SetValue(MaxValueProperty, value);
}public static readonly BindableProperty MaxValueProperty =
BindableProperty.Create("MaxValue", typeof(int), typeof(MainPage), 0, propertyChanged: OnMaxValueChanged);private static void OnMaxValueChanged(BindableObject bindable, object oldValue, object newValue) {
// ...
}

结论

WPF和.NET MAUI开发有许多共同之处,如果您熟悉WPF,可以毫不费力地创建一个功能强大的.NET MAUI应用程序。

 

http://www.dinnco.com/news/83587.html

相关文章:

  • 淄博学校网站建设方案万网域名管理入口
  • 上海红蚂蚁装潢设计有限公司官网seo兼职招聘
  • 如何做国际网站苏州网站建设费用
  • 如何建设购物网站seo软件推荐
  • 石家庄城乡建设网站无忧seo博客
  • 响应式网站开发毕业论文怎么制作网站平台
  • 做网站设计是什么专业磁力狗最佳搜索引擎
  • 网站开发社会可行性分析怎么写南宁最新消息今天
  • 单页网站如何做排名网站建成后应该如何推广
  • 商城网站开发企业市场营销策划公司
  • 渝快办重庆市网上办事大厅seo怎么优化方案
  • 十大接单网站北京网站seo设计
  • 移动互联网开发期末考试seo sem是啥
  • 网站前端是什么线上推广
  • 企业建站搭建谷歌关键词搜索排名
  • 街舞舞团公司做网站关键词优化策略
  • 深圳制作网站软件html家乡网站设计
  • 泉州建站模板搭建广州抖音推广
  • 个人电脑可以做网站服务器海外黄冈网站推广
  • wordpress 小工具 调用百度怎么优化关键词排名
  • 新注册域名做网站好处泰安做百度推广的公司
  • 福州商城网站开发公司高端网站定制
  • 淘宝客做网站可行么佛山seo优化外包
  • 做淘宝客的的网站有什么要求it行业培训机构哪个好
  • 政府网站和政务网站建设自查小程序怎么引流推广
  • wordpress utf8 gbk鹤壁seo
  • 如何做网站策划产品故事软文案例
  • 网站建设需要会什么软件有哪些深圳广告公司排名
  • 哈尔滨营销网站制作盐城seo营销
  • 邢台123今天最新招聘360搜索引擎优化