Quantcast
Channel: Developer Express Global
Viewing all articles
Browse latest Browse all 3388

Blog Post: .NET MAUI — Early Access Preview (v24.2) & Minor Update Enhancements (v24.1.5)

$
0
0
In this blog post, I’ll outline enhancements available in our early access preview (EAP v24.2) build. The post includes new features we expect to ship in our next major release (v24.2) and enhancements made in official minor updates (v24.1.4, v24.1.5).

Early Access Preview (v24.2)

To download/install our EAP, check “Include prerelease” when using the DevExpress NuGet feed:


Early Access and CTP builds are provided solely for early testing purposes and are not ready for production use. This build can be installed side by side with other major versions of DevExpress products. Please back up your project and other important data before installing Early Access and CTP builds.

This EAP may not include all features/products we expect to ship in our v24.2 release cycle. As its name implies, the EAP offers an early preview of what we expect to ship in two months. For additional information on what you can expect, refer to our Year-End 2024.2 Roadmap.

Ease of Use and IDE Integration

How long does it take to go from a blank page to a fully functional view? While the amount of time varies by project, the process typically involves the following steps:

  • Designing a mockup
  • Selecting appropriate UI components
  • Setting up control APIs
  • Implementing a view model to interact with business logic
And of course, each of these steps can be broken down into smaller tasks.

One of our primary goals for the upcoming major update (v24.2) is to streamline this entire process - helping you deliver intuitive mobile apps in the shortest possible time. 
To make this happen, we're introducing new project templates that include popular modules and pre-designed pages. While these templates aren't available in the current EAP release, I’d like to share our prototype with you...

In addition to templates, we're planning to introduce a toolbox packed with predefined XAML blocks, allowing you to design views by dragging items from the toolbox.

We understand that every app has unique requirements and predefined templates can't address each and every usage scenario. That's why we've made our building blocks flexible - use them as a foundation and customize them to suit your specific needs.

MVVM

We've developed a library of services, helpers, and markup extensions to make it easier to create MVVM-based applications. We didn’t create our own MVVM framework (as we did for WPF and WinForms components). Instead, we went with the Community Toolkit MVVM. Our library doesn’t replace it but enhances it with additional functionality.

Services

The following is a list of services our MVVM library includes:

  • NavigationService. Navigate between pages directly from your view model.
  • PrintServiceLaunch the default print dialog to print files.
  • SaveFilePicker. Open a dialog and allow users to save a file. 
These services are registered in the default Dependency Injection (DI) container. You simply need to register your view model and define a constructor that accepts corresponding interfaces to access the service within your view model.
public class ViewModel 
{ 
    public ViewModel(INavigationService navigationService, 
                     IPrintService printService, 
                     ISaveFilePicker saveFilePickerService) 
    { 
        //navigationService.GoToAsync(...); 
        //printService.PrintAsync(...); 
        //saveFilePickerService.SaveAsync(...); 
    } 
} 

If you prefer to use your own custom service implementation, you can register it in the DI container to override the default registration:

public static class MauiProgram 
{ 
    public static MauiApp CreateMauiApp() 
    { 
        //... 
        builder.Services.AddSingleton<INavigationService, NavigationServiceEx>(); 
    } 
} 
public class NavigationServiceEx : NavigationService { }
We've also implemented a UI service mechanism that allows you to interact with UI objects directly from your view model - without tying your code to a specific element type.
For instance, to force a CollectionView scroll to the last element, you can create a custom service that calls DXCollectionView.ScrollTo:
public interface IScollService  {  
    void ScrollToEnd();  
} 
public class ScollService : UIServiceBase, IScollService 
{ 
    public void ScrollToEnd() 
    { 
        DXCollectionView collection = (DXCollectionView)AssociatedObject; 
        collection.ScrollTo(collection.VisibleItemCount, DXScrollToPosition.End); 
    } 
} 
Once complete, you can attach this service to your DXCollectionView:
<dx:DXCollectionView> 
    <dx:DXCollectionView.Behaviors> 
        <local:ScollService/> 
    </dx:DXCollectionView.Behaviors> 
</dx:DXCollectionView > 
In your view model, you can access the registered service via the service container and trigger UI-related actions through the service interface:
public partial class ViewModel : IUIServiceClient 
{ 
    public IUIServiceContainer ServiceContainer { get; } = new UIServiceContainer(); 
  
    void ShowLastItem() 
    { 
        var scrollService = ServiceContainer.GetRequiredService<IScollService>(); 
        scrollService.ScrollToEnd(); 
    } 
} 

This technique allows you to invoke UI actions in a clean, MVVM-compliant manner. 

Dependency Injection

To simplify Dependency Injection, we've created a markup extension that allows you to assign a view model from the DI container directly in XAML: 

<ContentPage ... 
             xmlns:dx="http://schemas.devexpress.com/maui" 
             BindingContext="{dx:Ioc Type={x:Type vm:MainViewModel}}"> 
    public static class MauiProgram  { 
       public static MauiApp CreateMauiApp()   { 
           //... 
           builder.Services.AddTransient<ViewModel>(); 
       } 
  } 

With this extension, there's no need to create a constructor in your view to pass the view model and manually assign it to BindingContext  : 

//not required anymore
public MainPage(ViewModel viewModel) 
{ 
	BindingContext = viewModel; 
	InitializeComponent(); 
} 

The Ioc extension allows you to inject a view model into a view, even if the view itself isn't registered in the DI container. This will be useful when you have a  ContentView embedded within a parent page in XAML.

<ContentPage ...  
           x:Class="MauiExample.MainPage" > 
           <views:ChildContentView/> 
          <!--...--> 
</ContentPage> 
 
<ContentView ... 
             x:Class=" MauiExample.ChildContentView" 
             BindingContext="{dx:Ioc Type={x:Type vm:ChildViewModel}}"> 
    <!--...--> 
</ContentView> 

Collection View – Frozen Group Row

You can now keep group row headers visible while scrolling, as long as at least one child row in the group is on screen. Enable the DXCollectionView.AllowFixedGroupHeaders option to incorporate this feature in your DevExpress-powered .NET MAUI app. 

Asynchronous CRUD

As you know, both our .NET MAUI Collection View and .NET MAUI Data Grid controls include CRUD APIs to help you create detail and edit item forms. Since mobile apps often need to connect to remote services for data editing purposes, we've enhanced our CRUD APIs to support asynchronous operations.

Both the Collection View and Data Grid use CRUD view models to automatically transfer information between detail/edit views and handle actions like edit, save, and delete operations. We've made these commands asynchronous, so you can now execute them without freezing the UI. Additionally, we've added an IsAsyncOperationInProgress  property. This property allows you to display a loading indicator during asynchronous operations.

Data Grid Multi Selection

You can now enable multiple row selection in our Data Grid. Simply set DataGridView.SelectionMode to Multiple to activate this feature.

To retrieve selected rows in your view model, bind DataGridView.SelectedItems to a ObservableCollection<T> property type.

Minor Update (v24.1)

The following is a quick overview of new features included in recent minor updates. These features are included in our official releases, so you can start using them immediately by updating your NuGet packages to the most recent version.

Collection View & Tree View – Header & Footer

Headers and footers allow you to add custom elements above and below list items. Since they scroll alongside the rest of the view, this new feature helps make efficient use of available screen space. You can define any content for your header/footer (display elements that stand out from the rest of the list).

Here are a few ways to use headers and footers:

  • Display favorite items at the top.
  • Add a collection title.
  • Include a button to add more items or display the full list.

Collection View & Data Grid – Unlimited Height

When displaying a small collection within a scrollable layout, you might need to disable virtualization to ensure the collection takes up the space occupied by its items. This allows you to combine CollectionView with other elements inside a ScrollView, using one vertical scrollbar. We've introduced a new property to disable virtualization in CollectionView, allowing it to expand based on its child items.
Use the ReduceSizeToContent property to enable this feature.

Data Grid Immediate Posting

In earlier versions, Data Grid cell data was only posted to the source after the active editor was closed. While this is what you expect when working with text fields, you may prefer to post changes immediately in other column types (such as CheckBox columns). To address this requirement, we've introduced an option that updates the data source instantly when a cell is modified by a user.
To enable this mode, set EnableImmediatePosting to true.

PDF Viewer Print Command

We implemented a class to invoke native device printing dialogs. This feature is accessible via a built-in toolbar item in our .NET MAUI PDF Viewer control (or directly in code).

To invoke the dialog in code, call PdfViewer.PrintDocumentAsync.

Optimized Property Initialization

We’ve reduced the time needed to initialize controls before first use. 
Note: The following chart displays the time required for control initialization, not overall application startup or view opening time.

Chat Control Example


Our .NET MAUI Chat example is based on the DevExpress .NET MAUI CollectionView and includes the following options/capabilities:
  • Chat-inspired custom styled visual elements (DXCollectionView, TextEdit, DXButton).
  • Buttons for quick responses.
  • A fully-functional view model and basic business logic.
You can download the example from the following GitHub repository: Use DevExpress .NET MAUI Components to Build a Chat View

Your Feedback Matters


Viewing all articles
Browse latest Browse all 3388

Trending Articles