The cross platform MVVM framework MvvmCross, which is widely used abroad

The cross platform MVVM framework MvvmCross, which is widely used abroad

2022-10-10 0 825
Resource Number 44910 Last Updated 2025-02-24
¥ 0USD Upgrade VIP
Download Now Matters needing attention
Can't download? Please contact customer service to submit a link error!
Value-added Service: Installation Guide Environment Configuration Secondary Development Template Modification Source Code Installation

This issue recommends MvvmCross, a cross platform MVVM framework that enables developers to create powerful cross platform applications

The cross platform MVVM framework MvvmCross, which is widely used abroad插图

MvvmCross is a cross platform MVVM framework. It enables developers to create applications using MVVM mode onAndroid, Android, Android, Mac, Android, Universal Windows Platform (UWP), and Windows Presentation Framework (WPF). This allows you to share behavior and business logic between platforms, thereby achieving better code sharing

Functional Features

  • Use your own customizable binding engine to bind the VNet to Views, which allows you to create your own binding definitions for your custom views
  • VNet to VNet navigation, helping you share behavior on how and when to navigate
  • Implementing control reversal through dependency injection and attribute injection
  • Plugin framework allows you to insert cool things such as GPS positioning, localization, sensors, binding extensions, and a large number of 3rd easy plugin choices

The advanced features provided by MvvmCross are:

  • MVVM architecture pattern
  • Navigation system
  • Data binding
  • Platform details support
  • Control container inversion and dependency injection engine
  • Many commonly used plugins
  • Unit Test Assistant

Overview of MvvmCross

The deployed MvvmCross application consists of two parts:

  • “Core” – Contains all VNet, services, models, and “business” code
  • “UI” – Contains views and platform specific code that interact with “Core”

Alternatively, you can split the code into more projects/assemblies to improve reusability and decoupling layers
For multi platform applications, there are usually:

    A ‘core’ project written as NET Standard Library

  • Write the “UI” project for each platform as the native project for the current target platform
  • (Optional) Some other items may be NET Standard or platform libraries provide reusable abstract or specific functionality

The cross platform MVVM framework MvvmCross, which is widely used abroad插图1

How to start MvvmCross application

When the MvvmCross application starts, the actual situation is as follows:

    • The platform startup process is triggered

 

    In the construction of platform applications, Setup created MvvmCross

  • Setup executes framework initialization in two steps: Initialize Primary: runs on the main synchronization context (also known as the main thread). Initialize core components such as IoC and Logging mechanisms. Initialize Secondary: Run in the background (never on the main thread). Construct some other platform services, such as bindings, App classes, and Initialize calls to them. It ultimately registers for Views/ViewModels lookup
    When calling
  • App Initialize, your application should provide an AppStart object that is responsible for managing the first navigation step. The final step of setup initialization is to call AppStart Startup(object hint).
  • AppStart. Startup (object hint) runs and displays the first VNet/Views of your application

Note: If you want to know the parameter Startup on the method hint, you can use it to pass the initial parameters from your platform project to your core layer. For example, it is very useful when implementing push notifications

MvvmCross “Application” class

The MvvmCrossApp class should not be confused with objects in AppDelegateiOS, or with objects in AppAndroid or Windows. These are native, SDK provided objects, and this category is intended to be located in the common part of the code

Can the app register an IMvxAppStart object and register your own bit to the IoC. This is what it usually looks like:

using MvvmCross. Ioc;

namespace MyName. Core
{
public class App : MvvmCross. Core.ViewModels.MvxApplication
{
public override void Initialize()
{
CreatableTypes()
.EndingWith("Service")
.AsInterfaces()
.RegisterAsLazySingleton();

RegisterAppStart< ViewModels.MainViewModel> ();
// if you want to use a custom AppStart,  you should replace the previous line with this one:
// RegisterCustomAppStart< MyCustomAppStart> ();
}
}
}

In this code snippet, the first line performs batch registration of the IoC container. It looks at the current Assembly (the ‘core’ assembly) and uses reflection to register all services to delay the construction of singleton terminated classes

View Model

ViewModels are the key objects of the MVVM pattern. These should typically include code for managing status and operations. As the name suggests, VNet are view abstractions that provide properties and commands to be used

When using MvvmCross, all VNet should inherit from MvxViewModel These should usually include:

  • C # property that triggers changes
  • command
  • Private methods used for managing operations

This is the typical appearance of the VNet:

public class MainViewModel : MvxViewModel
{
public MainViewModel()
{
}

public override void Prepare()
{
// This is the first method to be called after construction
}
        
public override Task Initialize()
{
// Async initialization, YEY!</ span>
            
return base. Initialize();
}
        
public IMvxCommand ResetTextCommand => < span class="hljs-keyword">new MvxCommand(ResetText);

private void ResetText()
{
Text = "Hello MvvmCross";
}

private string _text = "Hello MvvmCross";
public string Text
{
get { return _text; }
set { SetProperty(ref _text, value); }
}
}

This MainVNet has:

    • Property that triggers a Property Changed notification when Text is changed

The command that ResetTextCommand calls every time a command is executed. ResetText()

MvvmCross package

MvvmCross is a very scalable framework. The community has already created many things that you can use. On this page, you will find the currently available MvvmCross Nuget packages

The cross platform MVVM framework MvvmCross, which is widely used abroad插图2

Android X

The cross platform MVVM framework MvvmCross, which is widely used abroad插图3

Plugin

The cross platform MVVM framework MvvmCross, which is widely used abroad插图4

Data binding

Core Windows Data Binding

    • C # properties are used for View and VNet
    • A single View property is “bound” – connected – to the VNet property
    • specifies a pattern that gives the direction of data flow (unidirectional, bidirectional, etc.)
    • You can choose to use ValueConverter to specify – this can also be parameterized

You can also choose to use FallbackValue to specify when binding fails</ li>

C # Properties and Data Binding

C # properties are used for data binding on Views and VNet

On the VNet, these properties are typically as follows:

private string _myProperty;
public string MyProperty
{
get =></ span> _myProperty;
set
{
_myProperty = value;
RaisePropertyChanged(() =></ span> MyProperty);
// take any additional actions here which are required when MyProperty is updated
}
}

Note: MvvmCross provides auxiliary methods to allocate support fields and triggers an event after checking if the value has actually changed. Consider using Set Property (), which exists in MvxVNet and above MvxProperty Changed. This mode uses local private support variables to store the current value and relies on RaisePeopleChanged to signal value changes to any listening view

Data binding properties

Using the View and VNet properties mentioned above, the value of the View property is typically modeled using the VNet C # property

For example:

    If your view contains CheckBoxes with the IsChecked property

  • So your VNet may contain a property:
private bool _rememberMe;
public bool RememberMe
{
get => _ rememberMe;
set =>  SetProperty(ref _rememberMe, value);
}
  • Then the binding may be IsChecked and connected together on the View with RememberMeVNet

—END—

Open source license: MS-PL License

资源下载此资源为免费资源立即下载
Telegram:@John_Software

Disclaimer: This article is published by a third party and represents the views of the author only and has nothing to do with this website. This site does not make any guarantee or commitment to the authenticity, completeness and timeliness of this article and all or part of its content, please readers for reference only, and please verify the relevant content. The publication or republication of articles by this website for the purpose of conveying more information does not mean that it endorses its views or confirms its description, nor does it mean that this website is responsible for its authenticity.

Ictcoder Free source code The cross platform MVVM framework MvvmCross, which is widely used abroad https://ictcoder.com/kyym/the-cross-platform-mvvm-framework-mvvmcross-which-is-widely-used-abroad.html

Share free open-source source code

Q&A
  • 1, automatic: after taking the photo, click the (download) link to download; 2. Manual: After taking the photo, contact the seller to issue it or contact the official to find the developer to ship.
View details
  • 1, the default transaction cycle of the source code: manual delivery of goods for 1-3 days, and the user payment amount will enter the platform guarantee until the completion of the transaction or 3-7 days can be issued, in case of disputes indefinitely extend the collection amount until the dispute is resolved or refunded!
View details
  • 1. Heptalon will permanently archive the process of trading between the two parties and the snapshots of the traded goods to ensure that the transaction is true, effective and safe! 2, Seven PAWS can not guarantee such as "permanent package update", "permanent technical support" and other similar transactions after the merchant commitment, please identify the buyer; 3, in the source code at the same time there is a website demonstration and picture demonstration, and the site is inconsistent with the diagram, the default according to the diagram as the dispute evaluation basis (except for special statements or agreement); 4, in the absence of "no legitimate basis for refund", the commodity written "once sold, no support for refund" and other similar statements, shall be deemed invalid; 5, before the shooting, the transaction content agreed by the two parties on QQ can also be the basis for dispute judgment (agreement and description of the conflict, the agreement shall prevail); 6, because the chat record can be used as the basis for dispute judgment, so when the two sides contact, only communicate with the other party on the QQ and mobile phone number left on the systemhere, in case the other party does not recognize self-commitment. 7, although the probability of disputes is very small, but be sure to retain such important information as chat records, mobile phone messages, etc., in case of disputes, it is convenient for seven PAWS to intervene in rapid processing.
View details
  • 1. As a third-party intermediary platform, Qichou protects the security of the transaction and the rights and interests of both buyers and sellers according to the transaction contract (commodity description, content agreed before the transaction); 2, non-platform online trading projects, any consequences have nothing to do with mutual site; No matter the seller for any reason to require offline transactions, please contact the management report.
View details

Related Article

make a comment
No comments available at the moment
Official customer service team

To solve your worries - 24 hours online professional service