Skip to content

This is an evolution of my frequently referenced 'CustomXamarinDemos' repository.

License

Notifications You must be signed in to change notification settings

LanceMcCarthy/CustomMauiExamples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Custom Maui Examples

This is an evolution of my frequently-referenced Custom Xamarin Demos repo, but strictly for .NET MAUI applications. This is where you will find helpful implementations of edge-case scenarios that fall outside the scope of support.

Demo Code
DataGrid - EFCore Demos and LoadOnDemand src/EFCoreDemos/
Chat - Advanced Data Sources src/ChatDataSources/
TabView Header Notification Badge src/TabHeaderNotification/
Captcha Control src/CaptchaControl/
Popup Service src/PopupServiceDemo/
Signature Editor src/SignatureEditor/
Custom Chart Legend src/ScatterWithLegend/
Printing Demo src/DocumentPrinting/
MAUI ReportViewer Demo src/CustomReportViewer/
Multi-Window TabView src/MultiWindowDemo/
DependencyInjection with TabView src/DepndInjtnDemo
gRPC Demo src/RealtimeDataSystem
Custom Controls (ColumnChooser, LabeledCheckBox, FloatingLabel, PartialRating, SegmentView) src/LantzControls
FlyoutPage Navigation src/FlyoutExample
Blazor Hybrid With Telerik XAML src/BlazorHybridWithTelerikXaml

PartialRating

EFCore Demos

This project contains DataGrid with automatic load on demand, fetching data from a database using EntityFrameworkCore.

datagrid and efcore

Chat with Advanced Data Sources

This demo contains a RadChat, directly connected to an entityFramework DBcontext.

chat

Future plans are to also include SignalR and gRPC service sources.

TabView Header Notification Badge

This demo uses conditional logic, with a custom HeaderItem ControlTemplate to only show notification badges on specific tab headers. This is accomplished by combining information from both the TabViewHeaderItem context and the Label.Text value to determine if the Label should be visible for that specific tab.

image

Captcha Control

Create a custom CAPTCHA control using using multiple fonts and colors using .NET MAUI's CanvasView to render different random characters with AttributedText and the DrawText method.

captcha

Visit Microsoft's 'draw attributed text' documentation example to learn more.

Popup Service

This example uses .NET MAUI's new DependencyInjection system to register a popup service that can be used anywhere in the app. Please visit the README for information on how it works.

As a sneak peek, here is the service being used in a view model.

public class HomeViewModel
{
    private readonly PopupService popupService;

    public HomeViewModel(PopupService service)
    {
        this.popupService = service;
        
        OpenPopupCommand = new Command(OpenPopup);
    }

    public Command OpenPopupCommand { get; set; }

    private void OpenPopup()
    {
        var popupContent = CreatePopupContent();
        
        // ***** Open the popup ***** //
        popupService.OpenPopup(popupContent);
    }
    ...
}

Signature Editor

This demo shows how to dynamically load signatures and swap between edit-mode with the RadSignaturePad, and view-mode with the Image of the saved signature.

signature editor

When the app launches, it first checks to see if a signature was already saved. If there was a previous signature, it will load that and start in view-mode. Otherwise, it will start in edit-mode.

Custom Chart Legend

If you would like more control over the appearance of your chart legend, create a completely custom legend with minimal effort using a RadItemsControl and the chart's Loaded event. This demo shows you exactly how it's done, visit MainPage to see the code (Jump to code).

custom chart legend

Printing

In order to print in .NET MAUI, you must use the native platform APIs. On Windows, this also includes manually preparing the print preview. This example shows you how to print a PDF file on Windows, iOS, MacCatalyst, and Android (Jump to code).

The code is in the Helpers folder, with each platform having its's own class file. Here's the result when starting a print on Windows.

printing

This is very document specific, you will need to do different work for different document types as this demo project is simply a place for you to get started.

ReportViewer

This demo has a custom ReportViewer for .NET MAUI (Jump to code). That control's platform handler does two things:

  • On Windows, it uses the native winUI 3 ReportViewer throught he MAUI handler. This is a pure native Windows implementation.
  • On iOS, MacCatalyst, and Android: The HTML5 ReportViewer is used in a WebView thorugh BindableProperties to render reports.
<controls:MauiReportViewer 
    RestServiceUrl="https://webapifortelerikdemos.azurewebsites.net/api/reports"
    ReportName="Barcodes Report.trdp"/>

Runtime - Windows

Windows ReportViewer

For more information, see the code in the Handlers folder.

Multi-Window TabView

A custom project that demonstrates "tear-able tabs" with RadTabView and .NET MAUI's multi-window features. You can break off a tab from one window and it will be moved to the new window instance (Jump to code).

Before

before

After

after

The buttons in the tab headers also let you move tabs left or right.

TabViewItems with Dependency Injection

This demo shows you how you can leverage .NET MAUI's built-in Dependency Injection to achieve IoC with your views and view models (Jump to code).

image

gRPC Demo

This example comes with both the server and client projects. It uses a DataGrid to show results form real-time stock trades (Jump to code).

Please refer to Microsoft gRPC documentation for more information about gRPC in a .NET application.

Lantz Controls

This is project that has various custom controls and will evolve over time as I add more (Jump to code).

  • FloatingLabel
  • LabeledCheckBox
  • ColumnChooser
  • PartialRating
  • SegmentView

FloatingLabel

Unfocused with RadEntry

unfocused

Focused with RadEntry

focused empty

Focused with RadEntry and Text Content

focused filled

ColumnChooser

Can be attached to any RadDataGrid to allow the app user to show/hide any column.

image

<Grid ColumnDefinitions="*, Auto">
    <telerik:RadDataGrid x:Name="MyDataGrid"
                         AutoGenerateColumns="False">
        <telerik:RadDataGrid.Columns>
            <telerik:DataGridTextColumn PropertyName="Name" HeaderText="Name" />
            <telerik:DataGridNumericalColumn PropertyName="Age" HeaderText="Age" />
            <telerik:DataGridDateColumn PropertyName="DateOfBirth" HeaderText="DOB" CellContentFormat="{}{0:MM/dd/yyyy}" />
        </telerik:RadDataGrid.Columns>
    </telerik:RadDataGrid>

    <!-- Associate with a DataGrid -->
    <dataGrid:ColumnChooser x:Name="Chooser"
                            AssociatedDataGrid="{x:Reference MyDataGrid}"
                            Margin="20"
                            Grid.Column="1" />
</Grid>

PartialRating

A rating control that can render fractional values.

PartialRating

Source:

Example

<input:PartialRating x:Name="RottenTomatoesRating"/>
private void Button_OnClicked(object sender, EventArgs e)
{
    var rating = Random.Shared.Next(0,5) + Random.Shared.NextDouble();

    RottenTomatoesRating.SetRating(rating);
}

SegmentView

SegmentView

Source:

Example

<input:SegmentView x:Name="MySegmentView"
                   SelectedSegmentTextColor="#036ecb"
                   SelectedSegmentBackgroundColor="#e0edf8"
                   BackgroundColor="White"
                   BorderColor="#e1e1e1"
                   CornerRadius="4"
                   FontSize="12"
                   HeightRequest="30"
                   Margin="5" />
MySegmentView.ItemsSource = [
    new SegmentItem() { Text = "Breakfast", ImageSource = ImageSource.FromFile("breakfast.png") },
    new SegmentItem() { Text = "Lunch", ImageSource = ImageSource.FromFile("lunch.png") },
    new SegmentItem() { Text = "Dinner", ImageSource = ImageSource.FromFile("dinner.png") }
];

FlyoutPage Navigation

This demo shows you how you can use FlyoutPage to navigate around an application (Jump to code). It shows you both top level and drill-down details page navigation without using Shell.

On initial launch, the FlyoutPage's Detail property is set to an instance of a ContentPage for authentication.

Initial Launch

After signing in, the Detail of the FlyoutPage is replaced with a NavigationPage. The lets the user navigate around the app using the menu on the left.

  • That menu is actually a ContentPage hosted by the FlyputPage.Flyout property.
  • The area on the right is a "RoutesPage" ContentPage hosted in a NavigationPage which is set to the FlyoutPage.Detail

Routes Page

Finally, because the FlyoutPage.Detail is a NavigationPage, we can 'drill-down' navigate from the RoutesPage to a "RouteDetailPage" while still technically being on the Routes page that was selected in the menu.

Route Details Page

Blazor Hybrid With Telerik XAML

This demo shows you how you can access the XAML part of a .NET MAUI Blazor Hybrid application (Jump to code). It uses a simple RadPopup, but the concept applies to anything else you might want to do on top of the BlazorWebView.

About

This is an evolution of my frequently referenced 'CustomXamarinDemos' repository.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published