美学原理基于Prism.Windows的UWP开发备忘

系列注册

UWP开发之Mvvmlight实践九:基于MVVM的体系架构分享

        public MenuViewModel(INavigationService navigationService, 

有了它再也不用担心一些卓越的页面漂移难题。

 

[Required(ErrorMessage = "Name is required.")]
public string Name
{
    get { return name; }
    set { SetProperty(ref name, value); }
}

[RegularExpression(@"[ABCD]\d{2,5}", ErrorMessage="Location is Quadrant (A -> D) and Sector (2 -> 5 digits)")]
public string Location
{
    get { return location; }
    set { SetProperty(ref location, value); }
}

 

            };

UWP开发之Mvvmlight实践五:SuspensionManager中断挂起以及复原处理

注意:

 

App.cs内部的CreateShell方法中安装:

ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver(
    viewType => {

{

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
prism:ViewModelLocator.AutowireViewModel="True"
Title="MainPage">
  <StackLayout HorizontalOptions="Center" VerticalOptions="Center">
    <Label Text="{Binding Title}" />
  </StackLayout>
</ContentPage>

            viewType =>

 resourceLoader)

        {

            _navigationService = navigationService;

            Commands = new ObservableCollection<MenuItemViewModel>

            {

                new MenuItemViewModel { DisplayName = resourceLoader.GetString("MainPageMenuItemDisplayName"), FontIcon = "\ue15f", Command = new DelegateCommand(NavigateToMainPage, CanNavigateToMainPage) },

                new MenuItemViewModel { DisplayName = resourceLoader.GetString("SecondPageMenuItemDisplayName"), FontIcon = "\ue19f", Command = new DelegateCommand(NavigateToSecondPage, CanNavigateToSecondPage) }

            };

        }
protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // 不要在窗口已包含内容时重复应用程序初始化,
            // 只需确保窗口处于活动状态
            if (rootFrame == null)
            {
                // 创建要充当导航上下文的框架,并导航到第一页
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: 从之前挂起的应用程序加载状态
                }

                // 将框架放在当前窗口中
                Window.Current.Content = rootFrame;
            }

            if (e.PrelaunchActivated == false)
            {
                if (rootFrame.Content == null)
                {
                    // 数据库创建
                    createDBAsync();
                    // 当导航堆栈尚未还原时,导航到第一页,
                    // 并通过将所需信息作为导航参数传入来配置
                    // 参数
                    rootFrame.Navigate(typeof(MainPage), e.Arguments);
                }
                // 确保当前窗口处于活动状态
                Window.Current.Activate();
            }
        }

        Task createDBAsync()
        {
            // 略
            return Task.FromResult(true);
        }

总计八:数据库创设时机

View名:HomePage

                return Type.GetType(viewModelName);

UWP开发之Mvvmlight实践四:{x:bind}和{Binding}不一样详解

Prism.Mvvm下ViewModelLocationProvide.cs的默许设置如下:
        static Func<Type, Type>
_defaultViewTypeToViewModelTypeResolver =

总结三:NavigationService

<TextBox Text="{Binding Name, Mode=TwoWay}" Header="Name" /> 

<TextBlock Text="{Binding Errors[Name][0]}" Foreground="Red" HorizontalAlignment="Right" />

 

<ItemsControl x:Name="ErrorList" ItemsSource="{Binding Errors.Errors}" />

 

UWP开发之Mvvmlight实践三:简单MVVM实例开发(图文详解付代码)

ValidatableBindableBase

            {

    Container.RegisterType<ISettingService, SettingService>(new
ContainerControlledLifetimeManager());

                var viewModelName =
String.Format(CultureInfo.InvariantCulture, “{0}{1}, {2}”, viewName,
suffix, viewAssemblyName);

  • App.cs内调用:

3,调用。

}

await
Container.Resolve<IAppStartupService>().CreateDataBaseAsync();

SessionStateService是接近SuspensionManager专门处理搁浅。

        protected override UIElement CreateShell(Frame rootFrame)
        {
            var menuPage = Container.Resolve<MenuPage>();
            menuPage.NavigationFrame.Content = rootFrame;
            return menuPage;
        }

 

                var viewName = viewType.FullName;

一旦View与ViewModel分层了,通过自定义ViewModelTypeResolver也得以兑现机关绑定。

说不上Views与ViewModels文件夹最好在同一个顺序集下,然后View的底部添加如下两行代码,就可以活动绑定ViewModel。

// 启动页面表示

NavigationService.Navigate("Home", null);

2,看重注入。(最好所有的流入都写在这么些方式里面,后续的开行处理以及页面转移等得以及时采纳。)

2,成员设置:

<prismMvvm:SessionStateAwarePage

 x:Class="PrismUnityApp1.Views.SettingPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:prismMvvm="using:Prism.Windows.Mvvm"
prismMvvm:ViewModelLocator.AutoWireViewModel="True"

mc:Ignorable="d">

 

                var viewAssemblyName =
viewType.GetTypeInfo().Assembly.FullName;

统计四:中断还原处理

        private INavigationService _navigationService;

        public HomePageViewModel(INavigationService navigationService)
        {
            _navigationService = navigationService;
        }

 

_navigationService.ClearHistory()等

 

 

 

动用办法(例如:Unity):

IResourceLoader

UWP开发之Mvvmlight实践八:为何事件注销处理要写在OnNavigatingFrom中

 

protected override Task OnInitializeAsync(IActivatedEventArgs args)
{
   
Container.RegisterInstance<INavigationService>(NavigationService);
   
Container.RegisterInstance<ISessionStateService>(SessionStateService);

4,.net
native相关的Default.rd.xml设置

2,调用GetString()获取数据。

 

private ObservableCollection<FavoriteInfo> _favoriteFolders;
[RestorableState]
public ObservableCollection<FavoriteInfo> FavoriteFolders
{     

  get     {         return _favoriteFolders;     }     

  set     {         SetProperty(ref _favoriteFolders, value);     }
}

 

就像是Asp.net
MVC支持以下Validation:

public class Address : 

眼前只襄助Unity,SimpleInjector,Autofac多少个,比较MvvmCross或者Mvvmlight框架则采取尤其灵活。

  1. bool Navigate(string pageToken,
    object parameter);
  2. void GoBack();
  3. bool CanGoBack();
  4. void GoForward();
  5. bool CanGoForward();
  6. void ClearHistory();
  7. void RemoveFirstPage(string
    pageToken = null, object parameter = null);
  8. void RemoveLastPage(string
    pageToken = null, object parameter = null);
  9. void RemoveAllPages(string
    pageToken = null, object parameter = null);
  10. void
    RestoreSavedNavigation();
  11. void Suspending();

UWP开发必备以及常用知识点计算

鉴于Prism封装了Application类,所以代码添加的岗位也变了:

 

2,ViewModel使用。

依傍注入

小结一:IOC控制反转容器

3,控件绑定

1,App.cs内部选取。(类以及含有NavigationService成员属性):

private INavigationService _navigationService; 
public HomePageViewModel(INavigationService navigationService)
{     _navigationService = navigationService;
}

 

行使方式:1,继承与ValidatableBindableBase

所有接口:

                var suffix = viewName.EndsWith(“View”) ? “Model” :
“ViewModel”;

 

小结二:自动绑定

protected override Task OnInitializeAsync(IActivatedEventArgs args)
        {
            createDBAsync();
            return base.OnInitializeAsync(args);
        }
sealed partial class App : PrismUnityApplication
    {}

计算七:菜单设置时机

机关绑定的命名规则:

UWP开发之Mvvmlight实践二:Mvvmlight的着力框架MVVM与MVC、MVP的区分(图文详解)

3,ViewModel中多少成员属性设置

  • Required
  • CreditCard
  • EmailAddress
  • PhoneNumber
  • Range
  • MinLength
  • MaxLenght
  • RegularExpression
  • Enumeration
  • URL
  • ViewModel内使用:

UWP开发之Mvvmlight实践六:MissingMetadataException解决办法(.Net
Native下Default.rd.xml配置难点)

                viewName = viewName.Replace(“.Views.”,
“.ViewModels.”);

 1,依赖注入。

    return base.OnInitializeAsync(args);
}

小结六:属性验证Validatable

ViewModel名:HomePageViewModel

protected override void OnRegisterKnownTypesForSerialization()
{
SessionStateService.RegisterKnownType(typeof(FavoriteInfo));
SessionStateService.RegisterKnownType(typeof(ServerInfo));
 // 这个比较重要
SessionStateService.RegisterKnownType(typeof(ObservableCollection<FavoriteInfo>));
}

protected override Task OnInitializeAsync(IActivatedEventArgs args)

1,App.cs内部设置

备考:通过持续ValidationAttribute
可以自定义各类评释逻辑。

protected override Task OnInitializeAsync(IActivatedEventArgs args)
{
    Container.RegisterInstance<ISessionStateService>(SessionStateService);

UWP开发之Mvvmlight实践一:如何在类型中丰硕应用Mvvmlight(图文详解)

    return base.OnInitializeAsync(args);
}

 

总结五:ResourceLoader

UWP开发之Mvvmlight实践七:如何寻找设备(Mobile模拟器、实体手机、PC)中利用的Log等文件

return base.OnInitializeAsync(args);

开头俺们一般都是在OnLaunched方法内部添加如下代码落成:

是因为10,11
的记录封存与还原都是运用DataContractSerializer连串化,所以页面漂移参数最好利用字符串或者数字。

Container.RegisterInstance<IResourceLoader>(new
ResourceLoaderAdapter(new ResourceLoader()));

<Type Name="PrismUnityApp1.DataModels.FavoriteInfo" 
DataContractSerializer="Required Public" />        

<Namespace Name="System.Collections.ObjectModel" >        

  <TypeInstantiation Name="ObservableCollection"  Arguments="PrismUnityApp1.DataModels.FavoriteInfo"
DataContractSerializer="Required Public" />     

</Namespace>

 

出于开发效能考虑,将来打算都选择Prism或者Template10开支,其中许多的完结原理与MvvmLight相似。此次按照Prism.Windows落成的UWP应用固然作用不是那么复杂,不过基本上用全了Prism的名特优特性,特写下次篇做备忘。

从前做UWP开发都是使用MvvmLight,紧假如概括易上手,同时也写了重重MvvmLight的费用种类小说:

        // 自由设置
        return Type.GetType(“”);
    });

2,ViewPage类型设置

1,App类继承于IOC对应的Application类。

骨干就这一个事物,计算一下造福以后开发,同时也冀望对园友们有帮带。