5

Learning .NET MAUI – Part 14

 2 years ago
source link: https://jesseliberty.com/2022/07/17/learning-net-maui-part-14/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Learning .NET MAUI – Part 14

Have I thanked James Montemagno yet? His 4 hour training video is the foundation of this series of posts (with his permission).

Part 0 which kicks off this series is here.

Platform Specific Services

Now that we’ve covered platform services from MAUI, what about platform-specific issues? For example, iOS has to deal with the notch at the top of the screen, while Android, Windows, etc. do not. To solve this, add a namespace:

xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls"

If you just type xmlns:ios=ios it will offer the entire string for completion

After saving that, and still in the ContentPage element you can then add

ios:Page.UseSafeArea="True"

This avoids the kind of platform if/else statements we were used to.

Refresh

The refresh command is much easier to deal with in MAUI.

<RefreshView Command="{Binding GetZipCodesCommand}" IsRefreshing="{Binding IsRefreshing}">
    <CollectionView ItemsSource="{Binding Results}" SelectionMode="None">
 ...
      </CollectionView>
  </RefreshView>

As you can see, I’m surrounding the CollectionView with a RefreshView. The Refresh view takes two properties. You bind to the command to cause the refresh and you bind to the IsRefreshing boolean to tell it when to stop.

In my MainPage.xaml I add a IsRefreshing boolean. That’s it. The GetZipCodesAsync method already exists.

[ObservableProperty] 
public bool _isRefreshing;

To see it at work, press GetZipcodes, then when you see your list press Clear. Now pull down from the top and hey!presto! your list is refreshed.

CollectionView.ItemsLayout

There are a lot of things you can do with the CollectionsView, but this is really cool. You can tell it you want some control over the layout of its items, and in fact you can make two columns on Android for example, and then take advantage of the size of a Windows example and make it three columns.

<CollectionView ItemsSource="{Binding Results}" SelectionMode="None">
    <CollectionView.ItemsLayout>
        <GridItemsLayout Orientation="Vertical" 
                         Span="{OnIdiom Desktop=3, Default=2}" />
    </CollectionView.ItemsLayout>
    <CollectionView.ItemTemplate>
three-columns-800x400.jpg?resize=568%2C284&ssl=1

The source code for this post is here.

Related

Learning .NET Maui Part 1June 10, 2022In "Essentials"

Learning .NET MAUI – Part 13July 16, 2022In "Essentials"

Learning .NET MAUI – Part 8July 6, 2022In "Essentials"

This entry was posted in Essentials. Bookmark the permalink.

Recommend

  • 7

    협업툴 잔디jandi.com0:03 / 0:30

  • 4

    This is the final post in my series of replicating the UI for the Foodora app using .NET MAUI. In this post I’ll replicate the final page, namely the page that shows the details of a specific dish. The original design of the fourt...

  • 4
    • jesseliberty.com 2 years ago
    • Cache

    Learning .NET MAUI Part 2

    Learning .NET MAUI Part 2 As noted in part 0, I assume you are a Xamarin.Forms/C# programmer, familiar with Visual St...

  • 5
    • jesseliberty.com 2 years ago
    • Cache

    Learning .NET Maui Part 1

    Learning .NET Maui Part 1 As noted in part 0, I assume you are a Xamarin.Forms/C# programmer, familiar with Visual St...

  • 7
    • jesseliberty.com 2 years ago
    • Cache

    Learning .NET MAUI – Part 4

    Learning .NET MAUI – Part 4 We’ve seen how to get a single zip code and display it in a series of labels. Let’s use a collection to take a look at how we might deal with that in MAUI. To get started, we’ll create...

  • 3
    • jesseliberty.com 2 years ago
    • Cache

    Learning .NET MAUI – Part 5

    Learning .NET MAUI – Part 5 When last we looked, we were returning a few countries. Let’s use ZipWise’s ability to look up a city name and give us all the info about all matching cities. We’ll then have fun with...

  • 8
    • jesseliberty.com 2 years ago
    • Cache

    Learning .NET MAUI – Part 6

    Learning .NET MAUI – Part 6 I’m going to start off where we were at the end of Part 5, but this time instead of creating two labels (for State and Zip) I’m going to create one label with MultiBinding:

  • 1
    • jesseliberty.com 2 years ago
    • Cache

    Learning .NET MAUI – Part 13

    Learning .NET MAUI – Part 13 In this post we’ll do three things: Add a clear button to clear out the list of zip codesAdd the Connected service to make sure we have internet connection bef...

  • 1
    • jesseliberty.com 2 years ago
    • Cache

    Learning .NET MAUI – Part 12

    Learning .NET MAUI – Part 12 We left off displaying the zip codes and going to the details, but not displaying the selected zip code. Let’s fix that and clean some things up. Choosing from the list an...

  • 5
    • jesseliberty.com 2 years ago
    • Cache

    Learning .NET MAUI – Part 15 – SQLite

    Learning .NET MAUI – Part 15 – SQLite As an experienced XF programmer, you know that there are times you need a relational database, and SQLite has been the mobile db of choice for a very long time. In this post...

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK