0% found this document useful (0 votes)
78 views9 pages

Net Maui

NET MAUI

Uploaded by

amanahar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views9 pages

Net Maui

NET MAUI

Uploaded by

amanahar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Troubleshooting

Error:
Xamarin.iOS does not support running or debugging the previous built version of your project.
Please ensure your solution builds before running or debugging it.

Resolution Steps
1. In Developer Powershell, update the workload
a. Dotnet workload install ios
2. If Reboot Pending then Reboot
3. Clear out bin/debug folder and try building application

XML Live Preview


1. Right Pane
2. Can update XAML and see previews
3. Can click on element in XAML Live Preview and it will take to xaml markup

Live Visual Tree


1. Left Pane
2. Application Object Model and can select the dynamic element tree

Android Emulator
1. Android Device Manager
2. Start it up automatically
3. Pick a default emulator like pixel 5

Windows Subsystem for Android Barista

Hot Restart - Apple Local Device


1. Tools→Options→Hot Restart Enabled
2. Apple Developer account
3. Itunes
4. Login to Itunes with paid account
5. Connect physical device and wait for iTunes to show up
6. Restart windows a few times and ensure there are no pending

Folder Structure
1. Platforms
2. Resources
a. AppIcon
b. Fonts
c. Images
d. Raw
e. Spash
f. Styles
i. Colors.xaml
1. Primary Color
2. Secondary Color
ii. Styles.xaml
3. MauiProgram.cs
a. Maui AppBulder
b. UseMauiApp<App>();
c. Configure fonts
4. App.xaml
a. Merge Dictionaries
i. Colors
ii. Styles
b. MainPage= new AppShell();
5. AppShell.xaml
a. <Shell>
i. Attributes
1. Shell.FlyoutBehavior = “Flyout”
a. Flyout menu
2. Shell.TabBarIsVisible = “False”
a. Menu items Tab bar at bottom/top are visibile
3. BackgroundClolor = “Red”
a. Navigation bar color
4. FlyoutBackgroundColor = “Blue”
a. Background color of the flyout
5. FlyoutBackdrop = “Black”
a. When flyout is open - the color of the area to the right of it
ii. Children
1. <FlyoutItem>
b.
6. MainPage.xml
7.

Upgrading from .NET 6


To upgrade your projects from .NET 6 to .NET 7, open your csproj file and
change the target framework monikers (TFM) from 6 to 7.

Before:

<TargetFrameworks>net6.0-ios;net6.0-android;net6.0-maccatalyst;net6.0-
tizen</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))
and '$(MSBuildRuntimeType)' == 'Full'">$(TargetFrameworks);net6.0-
windows10.0.19041</TargetFrameworks>
After:

<TargetFrameworks>net7.0-ios;net7.0-android;net7.0-maccatalyst;net7.0-
tizen</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))
and '$(MSBuildRuntimeType)' == 'Full'">$(TargetFrameworks);net7.0-
windows10.0.19041</TargetFrameworks>
Feedback
We guide our investments in .NET MAUI based on your input. Here’s how
you can make an impact.

Workload error:
1. NETSDK1147 To build this project, the following workloads must be installed:
maccatalyst
2. To install these workloads, run the following command: dotnet workload restore .\
SoberNetworkCast.csproj

CommunityToolkit
1. Install Nuget package CommunityToolkit.Maui
2. ## Initializing - In order to use the .NET MAUI Community Toolkit you need to call the
extension method in your `MauiProgram.cs` file as follows:
a. In MauiProgram.cs intialize it in the CreateMauiApp() method with method on
builder
b. builder.UseMauiCommunityToolkit();
3. ## XAML usage - In order to make use of the toolkit within XAML you can use this
namespace:
a. xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
4. ## Further information - For more information please visit:
a. - Our documentation site:
https://docs.microsoft.com/dotnet/communitytoolkit/maui
b. Our GitHub repository: https://github.com/CommunityToolkit/Maui

Status Bar Behavior


1. Has the Clock , Battery, Wifi Indicator etc. on iOS and Android
2. Comes with a default color of purple in .net MAUI for Android and transparent in iOS
3. Setup Shell namespace
a. <Shell xmlns:mct="clr-
namespace:CommunityToolkit.Maui.Behaviors;assembly=CommunityToolkit.Mau
i"
4. Set Page Behavior
a. <Page.Behaviors>
<mct:StatusBarBehavior StatusBarColor="{StaticResource Tertiary}"
StatusBarStyle="Default"/>
</Page.Behaviors>
5. May need to have the following setting in Ios Info.plist

a.
6. Another way to do this in Android only is to go change the default colors in the
resources:
a. Platforms→Android → Resources→ values → colors.xml
b.

Storage Options
● Preferences - stores data in key value pairs (dictionary)
○ E.g. Settings
○ Should be primitive values cannot store references to large objects such as list,
collections, and arrays
○ Each OS implements it differently but we are abstracted in MAUI via an Interface
○ Set and Get Operations
■ Preferences.Set(“Username”.”Aman”);
■ Preferences.Get(“Username”)
● File System - stores loose files directly on the devices through file system access
○ Save the state of the application
○ Serialized User generated data (files and images) and raw data in json files or
list, collections, and arrays

○ App Sandbox - when working with loose files, we need to store them in a suitable
location in file system
■ String path = FileSystem.AppDataDirectory;
■ Apple has iOS guidelines where files should be stored
● Library folder - use when storing app or system generated data
(state)
○ This is content that we can recreate without the assistance
of the user
○ This is not backed up and would not be restored from
backup
○ String path = FileSystem.AppDataDirectory;
● Documents folder - use when storing user generated data
○ This is backed up and would be restored from backout
○ String docFolder =
Environment.GetFolderPath(Environment.SpecialFolder.M
yDocuments)
● Database - stores data in a relational database
○ When we have relationships between data or when we want to filter data over
time
○ Types of Databases
■ SQLLite
■ Can use CoachDb
■ If Cotlin or Swift can get at we, we can get at it using MAUI
SQLLite
● Standalone, in-process, zero configuration
● ACID Compliant
● Useful when we have relational data
● It is a file, and we need to stare it in the appropriate place (Documents on iOS)
● Lightweight cross-platform local database
● Has now become an industry standard for mobile applications

Entity Framework Core


● Gives us a first-class cross-platform data access API targeting SQL Server, Azure
Cosmos DB, MySQL, PostgreSQL, SQLite, Oracle and more
● Domain model friendly - plays well with existing c# objects
● Fluent configuration
● Swappable provider model
● Escape hatches - can implement Dapper for example or use own sql queries and call
stored procedures
● LINQ
● Performance
● Nuget package:
○ Microsoft.EntityFrameworkCore.Sqlite

SQLLite-net
● C# Wrapper around the native SQLite engine that .NET developers can use
● Nuget packages
○ sqlite-net-pcl (Portable Class Library -
○ QLitePCLRaw.provider.dynamic_cdecl
● An object-relational mapper (ORM)

● SQL Connection
○ We establish a connection to SQLite db from an app through a
SQLiteConnection object
■ using SQLite;
■ String filename = …
■ SQLiteConnection conn = new SQLiteConnection(filename)
● Model a SQLite table


○ An object-relational mapper where we can build our DB schema from c# classes
with Annotations on class names
■ Table: specify he name of the table if other than the class’s name
■ PrimaryKey
■ AutoIncrement
■ Column: specify the name of a column if other than the property name
■ MaxLength
■ Unique
● Basic Read and write operations
○ conn.Insert(userInstance)
○ conn.Table<User>().ToList();
○ conn.????Operations
○ Execute a SQLite query by using LINQ - the Table method retrieves all the rows
from a table
■ conn.Table<User>().Where(user=> user.Username ==
userName).ToList();


○ Fluent ish syntax


● Update and delete rows


● d

You might also like