Net Maui
Net Maui
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
Android Emulator
1. Android Device Manager
2. Start it up automatically
3. Pick a default emulator like pixel 5
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.
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
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
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