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

南京高端网站定制网站简繁体转换 js

南京高端网站定制,网站简繁体转换 js,网站代码案例,如何传图片做网站适用于初学者的 .NET MAUI | Microsoft Learn 记录微软Learn中用到的代码。文章比较粗糙,大部分是项目代码粘贴。想详细学习的可到上面的链接学习,代码可以从这里复制后直接运行。 练习中一共有两个页面: 1、MainPage.xaml 用于添加列表中的…

适用于初学者的 .NET MAUI | Microsoft Learn

记录微软Learn中用到的代码。文章比较粗糙,大部分是项目代码粘贴。想详细学习的可到上面的链接学习,代码可以从这里复制后直接运行。

练习中一共有两个页面:

1、MainPage.xaml 用于添加列表中的内容。主要功能有向列表中添加一项;左滑删除该项;点击该选项进入详情页面。

2、DetailPage.xaml 显示详细信息,实际上显示的很少。返回主界面。

用到的MVVM包有:

1、CommunityToolkit.Mvvm

接下来是MainPage.xaml代码:

<?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="MauiAppDemo1.MainPage"xmlns:viewmode="clr-namespace:MauiAppDemo1.ViewModel"x:DataType="viewmode:MainViewModel"><Grid RowDefinitions="100,Auto,*"ColumnDefinitions=".75*,.25*"Padding="10"RowSpacing="10"ColumnSpacing="10"><Image Grid.ColumnSpan="2"Source="dotnet_bot.png"Background="white"/><Entry Placeholder="Enter task"Text="{Binding Text}"Grid.Row="1"/><Button Text="Add"Command="{Binding AddCommand}"Grid.Row="1"Grid.Column="1"/><CollectionView Grid.Row="2" Grid.ColumnSpan="2"ItemsSource="{Binding Items}"SelectionMode="None"><!--<CollectionView.ItemsSource><x:Array Type="{x:Type x:String}"><x:String>Apples</x:String><x:String>Bananas</x:String><x:String>Oranges</x:String></x:Array></CollectionView.ItemsSource>--><CollectionView.ItemTemplate><DataTemplate x:DataType="{x:Type x:String}"><SwipeView><SwipeView.RightItems><SwipeItems>    <SwipeItem Text="Delete"BackgroundColor="Red"Command="{Binding Source={RelativeSource AncestorType={x:Type viewmode:MainViewModel}},Path=DeleteCommand}"CommandParameter="{Binding .}"/></SwipeItems></SwipeView.RightItems><Grid Padding="0,5"><Frame><Frame.GestureRecognizers><TapGestureRecognizer Command="{Binding Source={RelativeSource AncestorType={x:Type viewmode:MainViewModel}},Path=TapCommand}"CommandParameter="{Binding .}"/></Frame.GestureRecognizers><Label Text="{Binding .}"FontSize="24"/></Frame></Grid></SwipeView></DataTemplate></CollectionView.ItemTemplate></CollectionView></Grid></ContentPage>
using MauiAppDemo1.ViewModel;namespace MauiAppDemo1;public partial class MainPage : ContentPage
{int count = 0;public MainPage(MainViewModel vm){InitializeComponent();BindingContext = vm;}}
    using MauiAppDemo1.ViewModel;namespace MauiAppDemo1;public static class MauiProgram
{public static MauiApp CreateMauiApp(){var builder = MauiApp.CreateBuilder();builder.UseMauiApp<App>().ConfigureFonts(fonts =>{fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");});builder.Services.AddSingleton<MainPage>();builder.Services.AddSingleton<MainViewModel>();builder.Services.AddTransient<DetailPage>();builder.Services.AddSingleton<DetailViewModel>();		return builder.Build();}
}
namespace MauiAppDemo1;public partial class AppShell : Shell
{public AppShell(){InitializeComponent();Routing.RegisterRoute(nameof(DetailPage),typeof(DetailPage));}
}
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace MauiAppDemo1.ViewModel
{/// <summary>/// CommunityToolkit.Mvvm/// </summary>public partial class MainViewModel : ObservableObject{public MainViewModel(){items = new ObservableCollection<string>();}[ObservableProperty]ObservableCollection<string> items;[ObservableProperty]string text;[RelayCommand]void Add(){if (string.IsNullOrWhiteSpace(Text)) return;items.Add(Text);Text = string.Empty;}[RelayCommand]void Delete(string s){if (items.Contains(s)){items.Remove(s);}}[RelayCommand]  async Task Tap(string s){await Shell.Current.GoToAsync($"{nameof(DetailPage)}?Text={s}");}}/// <summary>/// 基本写法/// </summary>//public class MainViewModel : INotifyPropertyChanged//{//    string text;//    public string Text//    {//        get => text;//        set//        {//            text=value;//            OnPropertyChanged(nameof(Text));//        }//    }//    public event PropertyChangedEventHandler PropertyChanged;//    void OnPropertyChanged(string name)=>PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));//}
}

DetailPage.xaml

                

<?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="MauiAppDemo1.DetailPage"xmlns:viewmodel="clr-namespace:MauiAppDemo1.ViewModel"x:DataType="viewmodel:DetailViewModel"Title="DetailPage"><VerticalStackLayout Padding="20"><Label Text="{Binding Text}"FontSize="25"VerticalOptions="Center" HorizontalOptions="Center" /><Button Text="Go Back"Command="{Binding GoBackCommand}"/></VerticalStackLayout>
</ContentPage>
using MauiAppDemo1.ViewModel;namespace MauiAppDemo1;public partial class DetailPage : ContentPage
{public DetailPage(DetailViewModel vm){InitializeComponent();BindingContext = vm;}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;namespace MauiAppDemo1.ViewModel
{[QueryProperty("Text","Text")]public partial class DetailViewModel:ObservableObject{[ObservableProperty]string text;[RelayCommand]async Task GoBack(){await Shell.Current.GoToAsync("..");}}
}

http://www.yayakq.cn/news/741430/

相关文章:

  • 爱站网关键词查询公司展厅设计制作
  • 濂溪区建设局网站网站备案怎么弄
  • 网站建设经验鄂州seo多少钱
  • 根据一个网站仿做新网站是什么网站开发 网站 费用
  • 快速做网站流量数据统计分析宁夏网站营销推广
  • 网站备案最多需要多久龙岩天宫山可以开车上去吗
  • 黄冈商城网站建设弧度网站建设
  • html5网站怎么建设后台怎么弄网站建设怎样上传程序
  • 域名做网站出售合法吗网站seo是什么意
  • php网站开发进程状态新闻发稿计划
  • 手机网站开发应注意电商之家官网
  • 一家专门做软件的网站佛山网站设计师
  • 怎么样在服务器上建设网站高密市网站建设
  • 国企有没有必要建设网站wordpress 图文
  • 天津网站建设运营方案做团购网站需要什么
  • 比较著名的seo网站深圳seo网站推广方案
  • 中国建设银行网站首页签约wordpress用户登录注册插件
  • php制作电影网站网站开发合同是否是技术合同
  • 怎样找素材做网站wordpress系统优化
  • 品划网络做网站广西住房和城乡建设部官网
  • 网站建设需要考虑什么因素做哪些网站流量最大
  • 网站开发kpi不能上传wordpress
  • 老鹰网营销型网站建设优化防疫二十条措施
  • 重庆奉节网站建设公司推广文案格式
  • 做自适应网站对设计稿的要求网站建设服务器配置
  • python做网站是不是特别慢推广网站广告有哪些
  • 中国建设银行怎么添加卡网站宜宾移动网站建设
  • 劳务公司网站建设杭州网站建设推广
  • 小饭店普通装修seo的网站特征
  • 做电玩城设计的网站昆明旅游网站建设