Friday, July 22, 2022

Cloud Service Model

Iaas: Infrastcture as s service
This cloud service model is the closest to managing physical servers; a cloud provider will keep the hardware up-to-date, but operating system maintenance and network configuration is up to you as the cloud tenant. 

Paas: Platform as a service
This cloud service model is a managed hosting environment. The cloud provider manages the virtual machines and networking resources, and the cloud tenant deploys their applications into the managed hosting environment. 
Example: Azure app services

Saas: Software as a service
In this cloud service model, the cloud provider manages all aspects of the application environment, such as virtual machines, networking resources, data storage, and applications. The cloud tenant only needs to provide their data to the application managed by the cloud provider. 
Example: Microsoft Office 365

Friday, July 8, 2022

Storage options in .NET MAUI

 .NET MAUI provides multiple storage options for caching data locally on a device.

The three most commonly used options for storing data locally in a .NET MAUI app are:

  • Preferences: Stores data in key-value pairs
  • File system: Stores loose files directly on the device through file system access
  • Database: Stores data in a relational database
Preferences are convenient when you're working with simple pieces of data, such as user selections.
bool bUserDetails = ...; ... Preferences.Set("UserDetails", bUserDetails); ... var savedPreference = Preferences.Get("UserDetails", false);

The Preferences class also contains methods for determining whether a named preference exists (ContainsKey), deleting a preference (Remove), and removing all preference data (Clear).

Consume a REST service with HttpClient in .NET MAUI

HttpClient is a .NET class that an app can use to send HTTP requests and receive HTTP responses from a REST web service. The resources that the web service exposes are identified by a set of URIs. 

A REST web services enables a client to perform operations against data through a set of HTTP verbs.

Four most common are GET, POST, PUT, and DELETE.

  • The GET verb indicate that you want to retrieve a resource.
  • The POST verb indicate that you want to create a new resource.
  • The PUT verb indicate that you want to update a resource.
  • The DELETE verb indicate that you want to delete a resource.

Thursday, July 7, 2022

Styles in .NET MAUI

 A style is a collection of setters targeted at a specific type of control. .NET MAUI requires a target type so it can make sure that the properties in your setters exist on that type.

You typically define styles as resources inside a ResourceDictionary object. A resource dictionary makes it easy to use the style across multiple controls on the same page, or even across your entire application.



<Style x:Key="MyButtonStyle" TargetType="Button"> <Setter Property="BackgroundColor" Value="#2A84D3" /> <Setter Property="BorderColor" Value="#1C5F9B" />

<Setter Property="BorderWidth" Value="2" /> <Setter Property="TextColor" Value="Green" /> </Style>

Applying a Style

<Button Text="OK" Style="{StaticResource MyButtonStyle}" /> <Button Text="Cancel" Style="{StaticResource MyButtonStyle}" />

Use an implicit style for multiple controls

Suppose your UI has 20 buttons and you want to apply the same style to all of them. With what we know so far, you'd need to assign to the Style property on each button manually. I

An implicit style is a style that you add to a resource dictionary without giving it an x:Key identifier. Implicit styles are automatically applied to all controls of the specified TargetType object.


<ContentPage.Resources> <Style TargetType="Button"> <Setter Property="BackgroundColor" Value="Blue" /> <Setter Property="BorderColor" Value="Navy" /> ... </Style> </ContentPage.Resources>

Application level resource and style


<Application.Resources> <Color x:Key="MyTextColor">Blue</Color> </Application.Resources>

Wednesday, July 6, 2022

Resources in .Net MAUI

 A resource is like a symbolic constant from a programming language. You define it in one place and reference it everywhere you need it. Your code will be easier to read because you use a descriptive name instead of a "magic" value. If you need to change the value, you only need to update the definition.

Every .NET MAUI XAML page has a property named Resources that can hold a ResourceDictionary object. The property is null by default, so you'll need to create a dictionary instance before you can use it. 


<ContentPage.Resources> <ResourceDictionary> <Color x:Key="PageControlTextColor">Blue</Color> </ResourceDictionary> </ContentPage.Resources>



<Label TextColor="{StaticResource PageControlTextColor}" ... />

Set platform-specific values for a resource

<ContentPage.Resources> <OnPlatform x:Key="textColor" x:TypeArguments="Color"> <On Platform="iOS" Value="Silver" /> <On Platform="Android" Value="Green" /> <On Platform="WinUI" Value="Yellow" /> <On Platform="MacCatalyst" Value="Pink" /> </OnPlatform> </ContentPage.Resources> ... <Label TextColor="{StaticResource textColor}" ... />

Dynamic Resources

DynamicResource is another mark-up extension for looking up resources in a resource dictionary. It's similar to StaticResource in that it does a dictionary lookup when the target object is created. But it also listens for changes to the resource in the dictionary. If the resource value in the dictionary changes, DynamicResource automatically updates the UI.



<ContentPage ...>

<ContentPage.Resources> <Color x:Key="PanelBackgroundColor">Blue</Color> </ContentPage.Resources> <StackLayout BackgroundColor="{DynamicResource PanelBackgroundColor}"> ... </StackLayout> </ContentPage>


this.Resources["PanelBackgroundColor"] = Colors.Green;

Grid in .Net MAUI

 Grid is a layout panel that consists of rows and columns. 

Example 1:

<Grid> <Grid.RowDefinitions> <RowDefinition Height="200" /> <RowDefinition Height="Auto" /> <RowDefinition Height="1*" /> <RowDefinition Height="2*" /> </Grid.RowDefinitions> ... </Grid>

This can be shortened to:

<Grid RowDefinitions="200, Auto, 1*, 2*"> ... </Grid>

Example 2:

<Grid RowDefinitions="*, *, *" ColumnDefinitions="*, *"> <BoxView Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" BackgroundColor="Navy" /> </Grid>

StackLayout in .Net MAUI

 Stacking views in a vertical or horizontal list is a common design for user interfaces. Stacking views in a vertical or horizontal list is a common design for user interfaces.

In .NET MAUI, you can add views to a StackLayout in C# code or in XAML. 



<StackLayout x:Name="myStack"> </StackLayout>


public partial class MainPage : ContentPage { public MainPage() { InitializeComponent(); var a = new BoxView { BackgroundColor = Colors.Silver, HeightRequest = 30 }; var b = new BoxView { BackgroundColor = Colors.Blue, HeightRequest = 30 }; var c = new BoxView { BackgroundColor = Colors.Gray, HeightRequest = 30 }; myStack.Children.Add(a); myStack.Children.Add(b); myStack.Children.Add(c); } }

To do the same thing in XAML, nest the children inside the StackLayout tags. 

<StackLayout> <BoxView Color="Silver" /> <BoxView Color="Blue" /> <BoxView Color="Gray" /> </StackLayout>

Cloud Service Model

Iaas: Infrastcture as s service This cloud service model is the closest to managing physical servers; a cloud provider will keep the hardwar...