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 1,177
Resource Number 44910 Last Updated 2025-02-24
¥ 0HKD 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/the-cross-platform-mvvm-framework-mvvmcross-which-is-widely-used-abroad/

Share free open-source source code

Q&A
  • 1. Automatic: After making an online payment, click the (Download) link to download the source code; 2. Manual: Contact the seller or the official to check if the template is consistent. Then, place an order and make payment online. The seller ships the goods, and both parties inspect and confirm that there are no issues. ICTcoder will then settle the payment for the seller. Note: Please ensure to place your order and make payment through ICTcoder. If you do not place your order and make payment through ICTcoder, and the seller sends fake source code or encounters any issues, ICTcoder will not assist in resolving them, nor can we guarantee your funds!
View details
  • 1. Default transaction cycle for source code: The seller manually ships the goods within 1-3 days. The amount paid by the user will be held in escrow by ICTcoder until 7 days after the transaction is completed and both parties confirm that there are no issues. ICTcoder will then settle with the seller. In case of any disputes, ICTcoder will have staff to assist in handling until the dispute is resolved or a refund is made! If the buyer places an order and makes payment not through ICTcoder, any issues and disputes have nothing to do with ICTcoder, and ICTcoder will not be responsible for any liabilities!
View details
  • 1. ICTcoder will permanently archive the transaction process between both parties and snapshots of the traded goods to ensure the authenticity, validity, and security of the transaction! 2. ICTcoder cannot guarantee services such as "permanent package updates" and "permanent technical support" after the merchant's commitment. Buyers are advised to identify these services on their own. If necessary, they can contact ICTcoder for assistance; 3. When both website demonstration and image demonstration exist in the source code, and the text descriptions of the website and images are inconsistent, the text description of the image shall prevail as the basis for dispute resolution (excluding special statements or agreements); 4. If there is no statement such as "no legal basis for refund" or similar content, any indication on the product that "once sold, no refunds will be supported" or other similar declarations shall be deemed invalid; 5. Before the buyer places an order and makes payment, the transaction details agreed upon by both parties via WhatsApp or email can also serve as the basis for dispute resolution (in case of any inconsistency between the agreement and the description of the conflict, the agreement shall prevail); 6. Since chat records and email records can serve as the basis for dispute resolution, both parties should only communicate with each other through the contact information left on the system when contacting each other, in order to prevent the other party from denying their own commitments. 7. Although the probability of disputes is low, it is essential to retain important information such as chat records, text messages, and email records, in case a dispute arises, so that ICTcoder can intervene quickly.
View details
  • 1. As a third-party intermediary platform, ICTcoder solely protects transaction security and the rights and interests of both buyers and sellers based on the transaction contract (product description, agreed content before the transaction); 2. For online trading projects not on the ICTcoder platform, any consequences are unrelated to this platform; regardless of the reason why the seller requests an offline transaction, please contact the administrator to report.
View details

Related Source code

ICTcoder Customer Service

24-hour online professional services