现在网站做SEO怎么样,珠海网站建设zhkmkj,代运营公司是做什么的,建设网站的五个步骤是详细内容这一期分享的内容非常简单#xff0c;在之前使用过WPF的开发者对MVVM开发模式下ViewModel中后台线程转UI线程并不陌生使用Appplication.Current.Dispatcher。那么在.NET MAUI中也有同样的机制#xff0c;存在于.NET MAUI Shell对象中。那么什么是Shell#xff1f;官…详细内容这一期分享的内容非常简单在之前使用过WPF的开发者对MVVM开发模式下ViewModel中后台线程转UI线程并不陌生使用Appplication.Current.Dispatcher。那么在.NET MAUI中也有同样的机制存在于.NET MAUI Shell对象中。那么什么是Shell官网描述如下.NET 多平台应用 UI (.NET MAUI) Shell 通过提供大多数应用所需的基本功能包括用于描述应用的视觉层次结构的单个位置。常见的导航用户体验。基于 URI 的导航方案允许导航到应用中的任何页面。集成的搜索处理程序。其他内容就不搬运了大伙可以参考下面链接内容。refhttps://docs.microsoft.com/zh-cn/dotnet/maui/fundamentals/shell/接下来我们直接来看看实际运用是如何的代码如下using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace MauiApp1.ViewModels
{public class MainViewModel{public void Do() {//同步Shell.Current.Dispatcher.Dispatch(() {//code...});//异步非阻塞Shell.Current.Dispatcher.DispatchAsync(() {//code...});//延迟1sShell.Current.Dispatcher.DispatchDelayed(new TimeSpan(1000), () {//code...});}}
}如果在MVVM开发模式下还想在ViewModel中弹出消息框那么同样也可以在Shell中访问。using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace MauiApp1.ViewModels
{public class MainViewModel{public void Do() {Shell.Current.DisplayAlert(message title,message content,cancel);}}
}