[Home] Edit Article
Author Information
File Uploads
Edit Article XML Content
<document> <header> <issuecode /> <articlecode /> <zone /> <title>Exploring .NET MAUI: Styles, Navigation, and Reusable UI</title> <authors /> <copyright>CODE Magazine</copyright> <owner>CODE Magazine</owner> </header> <body> <p id="0">In Part 1 of this ongoing series on developing an application in .NET MAUI (https://tinyurl.com/3vz3f5j7), you learned the basics of XAML, XML namespaces, attributes, and elements. You created your first .NET MAUI application and ran that application on both a Windows computer and an Android emulator. And you learned how to lay out a basic data-entry page using a Grid and Stack Layouts.</p> <p id="1">In this article, you’ll learn to apply styles so all pages in your application look consistent. You’ll create several pages and learn how to use the built-in navigation to move from one page to another. Using a ContentView control, you’ll create a header with data bindings that you can reuse on all pages in your application. Finally, you’ll add a border and a scroll viewer around all your controls.</p> <h2>Applying Styles to Your Controls</h2> <p id="2">In the XAML you wrote in the previous article Exploring .NET MAUI: Getting Started (https://tinyurl.com/3vz3f5j7), you added attributes to many of the same types of controls to change the <b>Margin</b>, <b>Padding</b>, and <b>Spacing</b> properties. The problem with adding these attributes to individual controls is that if you wish to change them, you must find them all and change them one-by-one. Instead of applying attributes on each control, create a <b>Style</b> element to specify which attributes you wish to apply to all controls of the same type. For example, you can create a style that applies to all Label controls or to all Grid controls. Styles avoid you having to set the attributes on individual controls.</p> <p id="3">There are a few different locations you may place these Style elements. Where you place them has different ramifications as to how those styles are applied to the controls. For example, if you create styles within a ContentPage, those styles are only available on that one page and no others. If you create styles in the App.xaml file, those styles are applied to all pages within the application. You may even create styles in a Class Library that allows many different .NET MAUI applications to reuse those same styles.</p> <h3>Creating Style Elements</h3> <p id="4">Style elements belong inside a <Resources> element. A <Resources> element can be within a single control, on a ContentPage, for the whole application, and within resource dictionary files. The <Style> starting tag must contain a <b>TargetType</b> property into which you specify the type of control to target, as shown below.</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">Style</font> <font color="Blue">»</font> <font color="Red">TargetType</font> <font color="Blue">=</font> <font color="#A31515">"HorizontalStackLayout"</font> <font color="Blue">></font> </codesnippet> <codesnippet>»»//»Add»Setter»elements»here</codesnippet> <codesnippet> <font color="Blue"></</font> <font color="Blue">Style</font> <font color="Blue">></font> </codesnippet> <p id="5">Within the Style element, place one or more <Setter> elements. Each Setter element sets a single property to a specific value for the <b>TargetType</b> specified. For example, on a HorizontalStackLayout, you can set the Spacing property using the following Setter element. Assign to the <b>Property</b> attribute the name of the property on the HorizontalStackLayout you wish to set. Set the <b>Value</b> property to the value you want for that property, as shown in the code snippet below.</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">Style</font> <font color="Blue">»</font> <font color="Red">TargetType</font> <font color="Blue">=</font> <font color="#A31515">"HorizontalStackLayout"</font> <font color="Blue">></font> </codesnippet> <codesnippet> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"Spacing"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"5"</font> <font color="Blue">»/></font> </codesnippet> <codesnippet> <font color="Blue"></</font> <font color="Blue">Style</font> <font color="Blue">></font> </codesnippet> <p id="6">If you place this style within a <ContentPage.Resources> element at the top of the ContentPage, all the <b>Spacing</b> properties on all HorizontalStackLayout controls are set to the value of five (5). If you place this style in the App.xaml file within the <Application.Resources> element, this style applies to all HorizontalStackLayout controls on all pages in the application.</p> <h3>Place Styles on the Content Page</h3> <p id="7">Let's start out by removing all the <b>Margin</b>, <b>Padding</b>, and <b>Spacing</b> properties from the XAML and place those settings into Style elements. Open the <b>MainPage.xaml</b> file and just after the starting <ContentPage> element and before the first starting <Grid> tag, add a new element called <ContentPage.Resources>, as shown in <b>Listing 1</b>.</p> <p id="8">Remove the <b>ColumnSpacing</b>, <b>RowSpacing</b>, <b>Margin</b>, and <b>Padding</b> from the <Grid> element on this page. Remove the <b>Spacing="5"</b> and <b>Padding="10"</b> from the <VerticalStackLayout> element on this page. <b>Remove</b> the <b>Spacing="5"</b> from all <HorizontalStackLayout> elements on this page.</p> <h3>Try It Out</h3> <p id="9">Run the application and notice that the spacing is still the same on the grid and stack layout controls as it was before you removed all the attributes. Also notice that the labels are aligned to each entry<b> </b>control appropriately.</p> <h3>Place Styles at the Application Level</h3> <p id="10">Instead of limiting the defined styles to affect only one page, let's move these styles out of the <ContentPage.Resources> section and move them to the application level so all pages will be styled the same. Open the <b>MainPage.xaml</b> file and cut all Style elements from the <ContentPage.Resources> element. Don't remove the <ContentPage.Resources> element from the page yet. Open the <b>App.xaml</b> file and paste the <Style> elements you copied <b>after</b> the </ResourceDictionary.MergedDictionaries> closing element and <b>before</b> the </ResourceDictionary> closing element.</p> <h3>Try It Out</h3> <p id="11">Most often when you change <Style> elements in the App.xaml file, you must restart the application for the changes to take effect. Restart the application and all the spacing should still be applied on your main page.</p> <h3>What’s a Resource Dictionary?</h3> <p id="12">In the previous exercise, you placed styles within a <ResourceDictionary> element. A <b>ResourceDictionary</b> is a set of resources that can be used in a .NET MAUI application. You may store styles, colors, string and number constants, and data templates within a ResourceDictionary. ResourceDictionary elements can be defined in the App.xaml file as you just saw, or you can create a ResourceDictionary within a separate XAML file, which you‘ll do later in this article.</p> <h3>Closest Style Wins</h3> <p id="13">Just like CSS in HTML, the closest style to the control it’s targeting will take precedence. For example, in the App.xaml file, you defined all Label controls to set their <b>VerticalOptions</b> property to "Center". However, open the <b>MainPage.xaml</b> file and add the Style within the <ContentPage.Resources> element from the next snippet. This Style element overrides the global style for all labels on this page because it’s closer to those controls.</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">Style</font> <font color="Blue">»</font> <font color="Red">TargetType</font> <font color="Blue">=</font> <font color="#A31515">"Label"</font> <font color="Blue">></font> </codesnippet> <codesnippet> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"</font> <font color="#A31515">VerticalOptions</font> <font color="#A31515">"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"</font> <font color="#A31515">End</font> <font color="#A31515">"</font> <font color="Blue">»/></font> </codesnippet> <codesnippet> <font color="Blue"></</font> <font color="Blue">Style</font> <font color="Blue">></font> </codesnippet> <h3>Try It Out</h3> <p id="14">Run the application and notice that all labels on this page are now positioned toward the bottom of each entry control. After you have observed this change, remove the <ContentPage.Resources> element from the MainPage.xaml so it goes back to using the global styles.</p> <h3>Keyed Styles</h3> <p id="15">All of the styles you created in the App.xaml file are called implicit styles because they implicitly affect all controls set with the <b>TargetType</b> property. Another kind of style is called a <b>Keyed Style</b>. A keyed style is where you set the <b>x:Key="UniqueName"</b> on the starting Style tag. Open the <b>App.xaml</b> file and change the <Style TargetType="Grid"> to add an x:Key attribute, as shown below.</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">Style</font> <font color="Blue">»</font> <font color="Red">TargetType</font> <font color="Blue">=</font> <font color="#A31515">"Grid"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»</font> <font color="Red">x:Key</font> <font color="Blue">=</font> <font color="#A31515">"Grid.Page"</font> <font color="Blue">></font> </codesnippet> <p id="16">Once you add the x:Key attribute, this style no longer affects all Grid controls. Instead, you need to explicitly reference this key name to apply it to a Grid control.</p> <h3>Try It Out</h3> <p id="17">To see that this style no longer affects a Grid, stop and restart the application to get the global styles to take effect. When the page is displayed, you should notice that the margins are missing on the Grid control.</p> <h3>Apply a Keyed Style</h3> <p id="18">To apply the <b>Grid.Page</b> keyed style to a Grid control, add the <b>Style</b> property on the Grid you want to apply the style to and reference the name of the key by using the StaticResource markup extension as shown below.</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">Grid</font> <font color="Blue">»</font> <font color="Red">RowDefinitions</font> <font color="Blue">=</font> <font color="#A31515">"Auto,Auto,Auto,»..."</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»</font> <font color="Red">ColumnDefinitions</font> <font color="Blue">=</font> <font color="#A31515">"Auto,*"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»</font> <font color="Red">Style</font> <font color="Blue">=</font> <font color="#A31515">"{StaticResource»Grid.Page}"</font> <font color="Blue">></font> </codesnippet> <p id="19">Within the double quotes for the Style property, you’re using curly braces and a <b>StaticResource</b> markup extension. Think of a markup extension as a .NET class that performs some service for you. In this case, the StaticResource extension searches for a resource defined with the x:Key attribute equal to the value "Grid.Page". When the StaticResource extension locates the resource, it applies any Setter values to the control it’s attached to.</p> <h3>Try It Out</h3> <p id="20">Restart the application and you should see that the spacing is once again being applied to the Grid control on your page.</p> <h3>Styling the Shell</h3> <p id="21">To make the title bar area stand out from the rest of the page, add a style to change the background color and the title color. Open the <b>App.xaml</b> file and add the following keyed style where you placed the other styles in this file.</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">Style</font> <font color="Blue">»</font> <font color="Red">TargetType</font> <font color="Blue">=</font> <font color="#A31515">"Element"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»</font> <font color="Red">x:Key</font> <font color="Blue">=</font> <font color="#A31515">"ShellStyle"</font> <font color="Blue">></font> </codesnippet> <codesnippet> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"Shell.BackgroundColor"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"Blue"</font> <font color="Blue">»/></font> </codesnippet> <codesnippet> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"Shell.TitleColor"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"White"</font> <font color="Blue">»/></font> </codesnippet> <codesnippet> <font color="Blue"></</font> <font color="Blue">Style</font> <font color="Blue">></font> </codesnippet> <p id="22">Open the <b>AppShell.xaml</b> file and in the <Shell> starting tag add the following <b>Style</b> attribute to apply the keyed style you just created named ShellStyle.</p> <codesnippet> <font color="Blue">Style</font>="{<font color="#A31515">StaticResource»ShellStyle</font>}"</codesnippet> <h3>Try It Out</h3> <p id="23">Restart the application and you should see that the title bar area is now white text on a blue background.</p> <h3>Place Styles in a Resource Dictionary File</h3> <p id="24">Within your Visual Studio project, drill down into the <b>Resources\Styles</b> folder and you should see two files; <b>Colors.xaml</b> and <b>Styles.xaml</b>. It’s in these two files where the default look is contained for the standard .NET MAUI controls. The Colors.xaml file contains several color resources. The Styles.xaml files uses the colors from the Colors.xaml file to define the look of the .NET MAUI controls as well as setting various properties such as Padding, Heights, Widths, and Fonts of the controls.</p> <p id="25">Open the <b>App.xaml</b> file and within the <ResourceDictionary> element where you placed your styles, there’s a <ResourceDictionary.MergedDictionaries> element in which you’ll find two ResourceDictionary elements with the <b>Source</b> property set to the Colors.xaml and Styles.xaml files respectively. As a normal practice, you’ll most likely place your styles after these two files because you’ll want to override the default styles.</p> <p id="26">Previously, you added styles directly in the App.xaml file. You’re now going to create your own Resource Dictionary file within the Resources\Styles folder and reference that file by adding your own ResourceDictionary in the <ResourceDictionary.MergedDictionaries> element. Right mouse-click on the <b>Resources\Styles</b> folder and select <b>Add > New Item… > .NET MAUI > .NET MAUI ResourceDictionary (XAML)</b> from the menu and set the name to <b>AppStyles.xaml</b>. Within the <ResourceDictionary> element in this new file, place the XAML shown in <b>Listing 2</b>.</p> <p id="27">Open the <b>App.xaml</b> file and just after the ResourceDictionary element that has the <b>Source</b> property set to <b>Resources/Styles/Styles.xaml</b>, add a reference to your new AppStyles.xaml file, as shown in the following XAML.</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">ResourceDictionary</font> </codesnippet> <codesnippet> <font color="Blue">»»»</font> <font color="Red">Source</font> <font color="Blue">=</font> <font color="#A31515">"</font> <font color="#A31515">Resources/Styles/AppStyles.xaml</font> <font color="#A31515">"</font> <font color="Blue">»/></font> </codesnippet> <p id="28">Because you added all the styles from the App.xaml file into your own resource dictionary file, you may now remove all the styles from the App.xaml file.</p> <h3>Try It Out</h3> <p id="29">Restart the application to ensure that your new AppStyles.xaml file is compiled and your page looks just like it did before.</p> <h3>Override a Style from the Styles.xaml File</h3> <p id="30">To further illustrate that your AppStyles.xaml file overrides the default styles created by Microsoft in the Styles.xaml file, let's change the text and background colors of the Button control. Open the <b>Resources\Styles\AppStyles.xaml</b> file and add the following Style element under the <b>Global Styles</b> comment.</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">Style</font> <font color="Blue">»</font> <font color="Red">TargetType</font> <font color="Blue">=</font> <font color="#A31515">"Button"</font> <font color="Blue">></font> </codesnippet> <codesnippet> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"TextColor"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"White"</font> <font color="Blue">»/></font> </codesnippet> <codesnippet> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"BackgroundColor"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"Black"</font> <font color="Blue">»/></font> </codesnippet> <codesnippet> <font color="Blue"></</font> <font color="Blue">Style</font> <font color="Blue">></font> </codesnippet> <h3>Try It Out</h3> <p id="31">Restart the application and you should see that the two buttons on your page have white text on a black background. Once you’ve verified that this works, remove the Button style you just added so it goes back to the default colors.</p> <h3>String Resources</h3> <p id="32">In a ResourceDictionary, you can create other types of resources besides styles. For example, you have repeated the string value "Adventure Works" twice in your application: once in the MainPage.xaml and once in the AppShell.xaml file. Instead of hard coding this string value in multiple places, open the <b>Resources\Styles\AppStyles.xaml</b> file and before all other styles, add the following keyed resource.</p> <codesnippet> <font color="Green"><!--»***************»--></font> </codesnippet> <codesnippet> <font color="Green"><!--»Other»Resources»--></font> </codesnippet> <codesnippet> <font color="Green"><!--»***************»--></font> </codesnippet> <codesnippet> <font color="Blue"><</font> <font color="Blue">x:String</font> <font color="Blue">»</font> <font color="Red">x:Key</font> <font color="Blue">=</font> <font color="#A31515">"ApplicationTitle"</font> <font color="Blue">></font> </codesnippet> <codesnippet>»»Adventure»Works</codesnippet> <codesnippet> <font color="Blue"></</font> <font color="Blue">x:String</font> <font color="Blue">></font> </codesnippet> <p id="33">Now that you have a keyed string resource, reference it from wherever in the application it is needed. Open the <b>AppShell.xaml</b> file and modify the <b>Title</b> property to reference this keyed resource using the StaticResource markup extension as shown in the following code:</p> <codesnippet>Title="{StaticResource»ApplicationTitle}"</codesnippet> <p id="34">Open the <b>MainPage.xaml</b> file and modify the <b>Title</b> property to reference this keyed resource using the StaticResource markup extension as shown in the following code:</p> <codesnippet>Title="{StaticResource»ApplicationTitle}"</codesnippet> <h3>Try It Out</h3> <p id="35">Run the application to ensure the title appears as you expect on the window shell and your page.</p> <h3>Numeric Resources</h3> <p id="36">In the <b>AppStyles.xaml</b> file, there are four <b>Value</b> properties in the Grid.Page keyed style set to the number ten (10). Instead of repeating the number ten that many times, create a double resource set to the number ten, as shown in the following XAML:</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">x:Double</font> <font color="Blue">»</font> <font color="Red">x:Key</font> <font color="Blue">=</font> <font color="#A31515">"DefaultSpacingForGrid"</font> <font color="Blue">></font> </codesnippet> <codesnippet>»»10</codesnippet> <codesnippet> <font color="Blue"></</font> <font color="Blue">x:Double</font> <font color="Blue">></font> </codesnippet> <p id="37">Modify the Grid.Page keyed style to use this new double resource by using the StaticResource markup extension in the Value attribute on each Setter as shown in the following XAML:</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">Style</font> <font color="Blue">»</font> <font color="Red">TargetType</font> <font color="Blue">=</font> <font color="#A31515">"Grid"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»</font> <font color="Red">x:Key</font> <font color="Blue">=</font> <font color="#A31515">"Grid.Page"</font> <font color="Blue">></font> </codesnippet> <codesnippet> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"ColumnSpacing"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"</font> <font color="#A31515">{StaticResource»</font> </codesnippet> <codesnippet> <font color="#A31515">»»»»»»»»»»»»»DefaultSpacingForGrid}</font> <font color="#A31515">"</font> <font color="Blue">»/></font> </codesnippet> <codesnippet> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"RowSpacing"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"</font> <font color="#A31515">{StaticResource</font> </codesnippet> <codesnippet> <font color="#A31515">»»»»»»»»»»»»»DefaultSpacingForGrid}</font> <font color="#A31515">"</font> <font color="Blue">»/></font> </codesnippet> <codesnippet> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"Margin"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"</font> <font color="#A31515">{StaticResource</font> </codesnippet> <codesnippet> <font color="#A31515">»»»»»»»»»»»»»DefaultSpacingForGrid}</font> <font color="#A31515">"</font> <font color="Blue">»/></font> </codesnippet> <codesnippet> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"Padding"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"</font> <font color="#A31515">{StaticResource</font> </codesnippet> <codesnippet> <font color="#A31515">»»»»»»»»»»»»»DefaultSpacingForGrid}</font> <font color="#A31515">"</font> <font color="Blue">»/></font> </codesnippet> <codesnippet> <font color="Blue"></</font> <font color="Blue">Style</font> <font color="Blue">></font> </codesnippet> <h3>Try It Out</h3> <p id="38">Restart the application and you should see that the spacing on the Grid is the same as it was before.</p> <h3>Create Styles in a .NET MAUI Class Library</h3> <p id="39">To create a set of styles that you can reuse across multiple .NET MAUI applications, place your styles into a .NET MAUI Class Library project. A class library project is a DLL (assembly) that can be referenced from any .NET MAUI application. Let's add one to the solution by right mouse-clicking on the solution and selecting <b>Add > New Project…</b> from the menu. Search for <b>.NET MAUI Class Library</b> and select that template.</p> <p id="40">Set the <b>Project name</b> field to <b>Common.Library.MAUI</b> and click the Next button. Choose the same .NET version you used to create your .NET MAUI application. Once the application is created, delete the <b>Class1.cs</b> file as this isn’t needed in this assembly.</p> <p id="41">I like keeping the same folder structure for my .NET MAUI Class Library projects as for the main application, so right mouse-click on the new project and select <b>Add > New Folder</b>. Set the name of this new folder to <b>Resources</b>. Right mouse-click on the Resources folder and select <b>Add > New Folder</b>. Set the name of this new folder to <b>Styles</b>.</p> <p id="42">Right mouse-click on the Styles folder and select <b>Add > New Item…</b> from the menu. Click on the <b>.NET MAUI</b> tab and select the template <b>.NET MAUI ResourceDictionary (XAML)</b>. Set the <b>Name</b> field to <b>CommonStyles.xaml</b>. After adding this new ResourceDictionary, add the XAML shown in <b /><b> REF _Ref163284371 \h \* MERGEFORMAT </b><b /><b /><b>Listing 3</b><b />. This is the same XAML you have in the AdventureWorks.MAUI project, but you’re going to delete that XAML in just a minute.</p> <p id="43">Go back to the <b>AdventureWorks.MAUI</b> project and right mouse-click on the <b>Dependencies</b> folder. Choose <b>Add Project Reference…</b> from the menu and add a reference to the <b>Common.Library.MAUI</b> project you just created. Open the <b>Resources\Styles\AppStyles.xaml</b> file in the AdventureWorks.MAUI project and remove everything from this file except the <b><x:String x:Key=ApplicationTitle"></b> element.</p> <p id="44">Open the <b>App.xaml</b> file and add an XML namespace to reference the ResourceDictionary namespace you created in the Common.Library.MAUI project, as shown in the following code. Due to space limitations of this article, I had to break this across multiple lines. Please make sure when adding to your project that the following is all on one line.</p> <codesnippet>xmlns:common="clr-namespace:</codesnippet> <codesnippet>»»Common.Library.MAUI.Resources.Styles;</codesnippet> <codesnippet>»»»»assembly=Common.Library.MAUI"</codesnippet> <p id="45">The CommonStyles.xaml file you created earlier has a partial class defined in the <b>CommonStyles.xaml.cs</b> file. This class, CommonStyles, is defined within the Common.Library.Resources.Styles namespace. The resources in the CommonStyles.xaml file are compiled into resources that you may now reference from the "common" XML namespace alias you added to App.xaml. Just before the <ResourceDictionary Source="Resources\Styles\AppStyles.xaml" /> element, add the following element.</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">common:CommonStyles</font> <font color="Blue">»/></font> </codesnippet> <p id="46">The styles from the CommonStyles.xaml file are now available for you to use throughout the AdventureWorks.MAUI application.</p> <h3>Try It Out</h3> <p id="47">Run the application and you should see that the main page still looks the same.</p> <h2>Create Several Pages</h2> <p id="48">So far, you’ve worked only with a single page, MainPage.xaml. In most applications, you’re going to have many different pages. You’re obviously going to need some way to navigate from one page to another. .NET MAUI has a nice navigation system built-in, but before you can learn about that, you need to create some pages, so let's do that now.</p> <h3>Create a User Detail Page</h3> <p id="49">I prefer to put all my pages underneath a folder named <b>Views</b>. Right mouse-click on the project and add a new folder named <b>Views</b>. Right mouse-click on the <b>Views</b> folder and select <b>Add > New Item > .NET MAUI > .NET MAUI ContentPage (XAML)…</b> from the context-sensitive menu. Set the Name of the page to <b>UserDetailView</b>. Once the page has been added, change the <b>Title</b> attribute on the ContentPage to "<b>User Information</b>". Delete the <VerticalStackLayout> element and all XAML within it on this new page. Open the <b>MainPage.xaml</b> file, cut the complete <Grid> element from this page and paste it into the ContentPage element on the UserDetailView.xaml file.</p> <h3>Update the Main Page</h3> <p id="50">Open the <b>MainPage.xaml</b> and where the <Grid> control was that you cut out, add the <Label> element you see in the following XAML snippet. The MainPage is only going to be used to show the application title in this article series. Other uses for the main page might be as a dashboard with large buttons to navigate to the pages most commonly used, or as description of the application.</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">Label</font> <font color="Blue">»</font> <font color="Red">Text</font> <font color="Blue">=</font> <font color="#A31515">"{StaticResource»ApplicationTitle}"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»</font> <font color="Red">FontSize</font> <font color="Blue">=</font> <font color="#A31515">"Large"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»</font> <font color="Red">VerticalOptions</font> <font color="Blue">=</font> <font color="#A31515">"Center"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»</font> <font color="Red">HorizontalOptions</font> <font color="Blue">=</font> <font color="#A31515">"Center"</font> <font color="Blue">»/></font> </codesnippet> <p id="51">Open the <b>MainPage.xaml.cs</b> file and cut the SaveButton_Clicked() event procedure and paste it into the <b>UserDetailView.xaml.cs</b> file.</p> <h3>Create Several More Pages</h3> <p id="52">You’re now going to create a few more content pages that you can navigate to in your application. On each page, you’re going to be adding a Label control with text to identify each page. Right mouse-click on the <b>Views</b> folder and add a new <b>.NET MAUI ContentPage (XAML)</b> named <b>LoginView</b>. Change the <b>Title</b> attribute to "Login". Replace the entire <VerticalStackLayout> element with the following XAML:</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">Label</font> <font color="Blue">»</font> <font color="Red">Text</font> <font color="Blue">=</font> <font color="#A31515">"Login"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»</font> <font color="Red">FontSize</font> <font color="Blue">=</font> <font color="#A31515">"Large"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»</font> <font color="Red">VerticalOptions</font> <font color="Blue">=</font> <font color="#A31515">"Center"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»</font> <font color="Red">HorizontalOptions</font> <font color="Blue">=</font> <font color="#A31515">"Center"</font> <font color="Blue">»/></font> </codesnippet> <p id="53">Right mouse-click on the <b>Views</b> folder and add a new <b>.NET MAUI ContentPage (XAML)</b> named <b>ProductDetailView</b>. Change the <b>Title</b> attribute to "Product Information". Replace the entire <VerticalStackLayout> element with the following XAML:</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">Label</font> <font color="Blue">»</font> <font color="Red">Text</font> <font color="Blue">=</font> <font color="#A31515">"Product»Information"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»</font> <font color="Red">FontSize</font> <font color="Blue">=</font> <font color="#A31515">"Large"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»</font> <font color="Red">VerticalOptions</font> <font color="Blue">=</font> <font color="#A31515">"Center"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»</font> <font color="Red">HorizontalOptions</font> <font color="Blue">=</font> <font color="#A31515">"Center"</font> <font color="Blue">»/></font> </codesnippet> <p id="54">Right mouse-click on the <b>Views</b> folder and add a new <b>.NET MAUI ContentPage (XAML)</b> named <b>CustomerDetailView</b>. Change the <b>Title</b> attribute to "Customer Information". Replace the entire <VerticalStackLayout> element with the following XAML:</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">Label</font> <font color="Blue">»</font> <font color="Red">Text</font> <font color="Blue">=</font> <font color="#A31515">"Customer»Information"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»</font> <font color="Red">FontSize</font> <font color="Blue">=</font> <font color="#A31515">"Large"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»</font> <font color="Red">VerticalOptions</font> <font color="Blue">=</font> <font color="#A31515">"Center"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»</font> <font color="Red">HorizontalOptions</font> <font color="Blue">=</font> <font color="#A31515">"Center"</font> <font color="Blue">»/></font> </codesnippet> <p id="55">Right mouse-click on the <b>Views</b> folder and add a new <b>.NET MAUI ContentPage (XAML)</b> named <b>ColorListView</b>. Change the <b>Title</b> attribute to "Color List". Replace the entire <VerticalStackLayout> element with the following XAML:</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">Label</font> <font color="Blue">»</font> <font color="Red">Text</font> <font color="Blue">=</font> <font color="#A31515">"Color»List"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»</font> <font color="Red">FontSize</font> <font color="Blue">=</font> <font color="#A31515">"Large"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»</font> <font color="Red">VerticalOptions</font> <font color="Blue">=</font> <font color="#A31515">"Center"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»</font> <font color="Red">HorizontalOptions</font> <font color="Blue">=</font> <font color="#A31515">"Center"</font> <font color="Blue">»/></font> </codesnippet> <p id="56">Right mouse-click on the <b>Views</b> folder and add a new <b>.NET MAUI ContentPage (XAML)</b> named <b>PhoneTypesListView</b>. Change the <b>Title</b> attribute to "Phone Types List". Replace the entire <VerticalStackLayout> element with the following XAML.</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">Label</font> <font color="Blue">»</font> <font color="Red">Text</font> <font color="Blue">=</font> <font color="#A31515">"Phone»Types»List"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»</font> <font color="Red">FontSize</font> <font color="Blue">=</font> <font color="#A31515">"Large"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»</font> <font color="Red">VerticalOptions</font> <font color="Blue">=</font> <font color="#A31515">"Center"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»</font> <font color="Red">HorizontalOptions</font> <font color="Blue">=</font> <font color="#A31515">"Center"</font> <font color="Blue">»/></font> </codesnippet> <h2>Navigation in .NET MAUI Applications</h2> <p id="57">Now that you have several pages created, it’s time to learn to navigate among the different pages. The Shell control in .NET MAUI uses a URI-based navigation scheme to route between different pages in your application. There are a few different types of navigation schemes that you may employ in your application. You may use a <b>FlyoutItem</b>, which is a tab bar for your application and is accessible through an icon, or by swiping from the side of the screen. Another navigation scheme is a <b>TabBar</b>, which is a set of tabs displayed either at the top or bottom of the screen depending upon which OS your application is running.</p> <p id="58">Regardless of which navigation scheme you choose, both <b>ShellContent</b> and <b>Tab </b>objects are used. A ShellContent object references a single page in your application to which you want to navigate. A Tab object is a wrapper around one or more ShellContent objects. If you’re running on Windows, a Tab object with more than one ShellContent object creates a drop-down set of tabs of the enclosed ShellContent objects. If you’re running on a mobile device, the Tab object appears as bottom tabs with the ShellContent objects within that Tab shown as top tabs when the bottom tab is selected.</p> <h3>The ShellContent Object</h3> <p id="59">The ShellContent object has many properties, but there are a few that you’ll set most often. The <b>Title</b> property is used to set the word(s) you want to display on the tab. The <b>Icon</b> property is the icon to display along with the text. You also have the <b>IsChecked</b>, <b>IsEnabled</b>, and <b>IsVisible</b> properties to set the currently highlighted tab, whether or not the current tab is enabled, or whether or not it’s visible, respectively. The <b>Route</b> property is an optional string to uniquely identify the tab/route. If you set the Route property, this property is used to navigate to that specific route. The <b>ContentTemplate</b> property is set to a reference of the actual page to display within the application shell. The syntax you use in the ContentTemplate property is a <b>DataTemplate</b> markup extension followed by the name of the page. For example, <b>ContentTemplate="{DataTemplate views:UserDetailView}"</b> navigates to the UserDetailView page you created.</p> <h3>Using TabBar Navigation</h3> <p id="60">Let's create a TabBar navigation system for the pages you’ve added to your .NET MAUI application. Because you added all of the pages to the Views folder, they’re located within the <b>AdventureWorks.MAUI.Views</b> namespace. Thus, if you want to use a page from the Views namespace in a ShellContent object, you need to add a reference to that namespace. Open the <b>AppShell.xaml</b> file and add a new XML namespace, as shown in the following code snippet. Please note that I had to break the line just after the colon so it fits within the printed version of this publication. The entire code should be on a single line when you add it to the <Shell> element.</p> <codesnippet>xmlns:views="clr-namespace:</codesnippet> <codesnippet>»»AdventureWorks.MAUI.Views"</codesnippet> <p id="61">The <Shell> element currently in the AppShell.xaml file is a single ShellContent object pointing to the MainPage. Delete that ShellContent object from within the <Shell> element and add the following XAML to display tabs to navigate to the home, the UserDetailView, the ProductDetailView, and the CustomerDetailView page:</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">TabBar</font> <font color="Blue">></font> </codesnippet> <codesnippet>»»<font color="Blue"><</font><font color="Blue">ShellContent</font><font color="Blue">»</font><font color="Red">Title</font><font color="Blue">=</font><font color="#A31515">"Home"</font></codesnippet> <codesnippet> <font color="Blue">»»»»</font> <font color="Red">ContentTemplate</font> <font color="Blue">=</font> <font color="#A31515">"{DataTemplate</font> </codesnippet> <codesnippet> <font color="#A31515">»»»»»»local:MainPage}"</font> <font color="Blue">»/></font> </codesnippet> <codesnippet>»»<font color="Blue"><</font><font color="Blue">ShellContent</font><font color="Blue">»</font><font color="Red">Title</font><font color="Blue">=</font><font color="#A31515">"Users"</font></codesnippet> <codesnippet> <font color="Blue">»»»»</font> <font color="Red">ContentTemplate</font> <font color="Blue">=</font> <font color="#A31515">"{DataTemplate</font> </codesnippet> <codesnippet> <font color="#A31515">»»»»»»views:UserDetailView}"</font> <font color="Blue">»/></font> </codesnippet> <codesnippet>»»<font color="Blue"><</font><font color="Blue">ShellContent</font><font color="Blue">»</font><font color="Red">Title</font><font color="Blue">=</font><font color="#A31515">"Products"</font></codesnippet> <codesnippet> <font color="Blue">»»»»</font> <font color="Red">ContentTemplate</font> <font color="Blue">=</font> <font color="#A31515">"{DataTemplate</font> </codesnippet> <codesnippet> <font color="#A31515">»»»»»»views:ProductDetailView}"</font> <font color="Blue">»/></font> </codesnippet> <codesnippet>»»<font color="Blue"><</font><font color="Blue">ShellContent</font><font color="Blue">»</font><font color="Red">Title</font><font color="Blue">=</font><font color="#A31515">"Customers"</font></codesnippet> <codesnippet> <font color="Blue">»»»»</font> <font color="Red">ContentTemplate</font> <font color="Blue">=</font> <font color="#A31515">"{DataTemplate</font> </codesnippet> <codesnippet> <font color="#A31515">»»»»»»views:CustomerDetailView}"</font> <font color="Blue">»/></font> </codesnippet> <codesnippet> <font color="Blue"></</font> <font color="Blue">TabBar</font> <font color="Blue">></font> </codesnippet> <h3>Try It Out on Windows</h3> <p id="62">Run the application on <b>Windows</b> to display the window shell with the tabs shown in <b>Figure 1</b>. Click on each of the tab items to navigate to the corresponding pages. Finally, click on the <b>Home</b> tab to navigate back to the Main page.</p> <figure id="1" src="image1.png"> <b>Figure </b> <b>1:</b> Running the application on Windows displays tab items at the top of the window.</figure> <h3>Try It Out on the Android Emulator</h3> <p id="63">Change Visual Studio to run the application on the <b>Android</b> Emulator. The tabs should now be displayed at the bottom of the page, as shown in <b>Figure 2</b>. Click on each of the various tabs at the bottom of the page to navigate to the corresponding pages. Click on the <b>Home</b> menu to navigate back to the Main page.</p> <figure id="2" src="image2.png"> <b>Figure </b> <b>2:</b> ShellContent objects appear as a set of bottom tabs on an Android device.</figure> <h3>Display Subordinate Tabs</h3> <p id="64">You can create a tab that doesn’t directly navigate to a page, but instead displays a set of tabs either in a drop-down on Windows, or as a set of top tabs on an Android device. Open the <b>AppShell.xaml</b> file and immediately after the Customers ShellContent object, add the following XAML:</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">Tab</font> <font color="Blue">»</font> <font color="Red">Title</font> <font color="Blue">=</font> <font color="#A31515">"Maintenance"</font> <font color="Blue">></font> </codesnippet> <codesnippet>»»<font color="Blue"><</font><font color="Blue">ShellContent</font><font color="Blue">»</font><font color="Red">Title</font><font color="Blue">=</font><font color="#A31515">"Colors"</font></codesnippet> <codesnippet> <font color="Blue">»»»»</font> <font color="Red">ContentTemplate</font> <font color="Blue">=</font> <font color="#A31515">"{DataTemplate</font> </codesnippet> <codesnippet> <font color="#A31515">»»»»»»views:ColorListView}"</font> <font color="Blue">»/></font> </codesnippet> <codesnippet>»»<font color="Blue"><</font><font color="Blue">ShellContent</font><font color="Blue">»</font><font color="Red">Title</font><font color="Blue">=</font><font color="#A31515">"Phone»Types"</font></codesnippet> <codesnippet> <font color="Blue">»»»»</font> <font color="Red">ContentTemplate</font> <font color="Blue">=</font> <font color="#A31515">"{DataTemplate</font> </codesnippet> <codesnippet> <font color="#A31515">»»»»»»views:PhoneTypesListView}"</font> <font color="Blue">»/></font> </codesnippet> <codesnippet> <font color="Blue"></</font> <font color="Blue">Tab</font> <font color="Blue">></font> </codesnippet> <codesnippet> <font color="Blue"><</font> <font color="Blue">ShellContent</font> <font color="Blue">»</font> <font color="Red">Title</font> <font color="Blue">=</font> <font color="#A31515">"Login"</font> </codesnippet> <codesnippet> <font color="Blue">»»</font> <font color="Red">ContentTemplate</font> <font color="Blue">=</font> <font color="#A31515">"{DataTemplate</font> </codesnippet> <codesnippet> <font color="#A31515">»»»»views:LoginView}"</font> <font color="Blue">»/></font> </codesnippet> <h3>Try It Out on Windows</h3> <p id="65">Restart the application on the <b>Windows Machine</b>, click on the down arrow next to the word Maintenance and you should see a drop-down list of tabs, as shown in <b>Figure 3</b>.</p> <figure id="3" src="image3.png"> <b>Figure </b> <b>3:</b> Display a set of drop-down tab items on Windows machines.</figure> <h3>Try It Out on the Android Emulator</h3> <p id="66">Stop the application and change Visual Studio to use the <b>Android</b> Emulator. Run the application and you should now see a <b>More...</b> tab displayed, as shown in <b>Figure 4</b>. When there are more than four tabs, this <b>More...</b> tab is displayed to allow you to get to the next set of tabs.</p> <figure id="4" src="image4.png"> <b>Figure </b> <b>4:</b> A More tab item is displayed when there are more tabs than fit within the displayable area on a mobile device.</figure> <p id="67">Click on the <b>More...</b> tab to see the <b>Maintenance</b> and <b>Login</b> tabs appear, as shown in <b>Figure 5</b>.</p> <figure id="5" src="image5.png"> <b>Figure </b> <b>5:</b> The next set of tabs are displayed after clicking on the More tab.</figure> <p id="68">Click on <b>Maintenance</b> and you should see <b>Colors</b> and <b>Phone Types</b> menus appear at the top of the screen, as shown in <b>Figure 6</b>.</p> <figure id="6" src="image6.png"> <b>Figure </b> <b>6:</b> ShellContent objects wrapped within a Tab object are displayed on the top bar on mobile devices.</figure> <h3>Programmatically Navigate from Page to Page</h3> <p id="69">Right mouse-click on the Views folder and add a new content page named <b>UserListView</b>. Set the <b>Title</b> attribute to "User List". Replace the <VerticalStackLayout> with the following XAML:</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">VerticalStackLayout</font> <font color="Blue">»</font> <font color="Red">VerticalOptions</font> <font color="Blue">=</font> <font color="#A31515">"Center"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»»»»»»»»»»»»»»»</font> <font color="Red">HorizontalOptions</font> <font color="Blue">=</font> <font color="#A31515">"Center"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»»»»»»»»»»»»»»»</font> <font color="Red">Spacing</font> <font color="Blue">=</font> <font color="#A31515">"10"</font> <font color="Blue">></font> </codesnippet> <codesnippet>»»<font color="Blue"><</font><font color="Blue">Label</font><font color="Blue">»</font><font color="Red">Text</font><font color="Blue">=</font><font color="#A31515">"User»List"</font></codesnippet> <codesnippet> <font color="Blue">»»»»»»»»»</font> <font color="Red">FontSize</font> <font color="Blue">=</font> <font color="#A31515">"Header"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»»»</font> <font color="Red">HorizontalOptions</font> <font color="Blue">=</font> <font color="#A31515">"Center"</font> <font color="Blue">»/></font> </codesnippet> <codesnippet>»»<font color="Blue"><</font><font color="Blue">Button</font><font color="Blue">»</font><font color="Red">Text</font><font color="Blue">=</font><font color="#A31515">"Navigate»to»Detail"</font></codesnippet> <codesnippet> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Clicked</font> <font color="Blue">=</font> <font color="#A31515">"NavigateToDetail_Clicked"</font> <font color="Blue">»/></font> </codesnippet> <codesnippet> <font color="Blue"></</font> <font color="Blue">VerticalStackLayout</font> <font color="Blue">></font> </codesnippet> <p id="70">Create the <b>Clicked</b> event procedure by positioning your cursor anywhere within the double quotes of the Clicked attribute. Press the F12 key and the NavigateToDetail_Clicked() event procedure stub is created for you. Modify the procedure declaration to include the <b>async</b> keyword and add a single line of code within the procedure, as shown in the following code snippet:</p> <codesnippet> <font color="Blue">private</font> <font>»</font> <font color="Blue">async</font> <font>»</font> <font color="Blue">void</font> <font>»</font> </codesnippet> <codesnippet> <font>»»</font> <font color="#A31515">NavigateToDetail_Clicked</font> <font>(</font> <font color="Blue">object</font> <font>»sender,</font> </codesnippet> <codesnippet> <font>»»»»EventArgs»e</font> <font>)</font> <font>»</font>{</codesnippet> <codesnippet> <font color="Blue">await</font> <font>»Shell.Current</font> </codesnippet> <codesnippet> <font>»»»».GoToAsync(</font> <font color="Blue">nameof</font> <font>(Views.UserDetailView));</font> </codesnippet> <codesnippet>}</codesnippet> <p id="71">In the above code, you access the application shell object through the Shell property of the ContentPage class to navigate to another page. Pass the name of the route to the GoToAsync() method and the Shell loads that page and displays it. Always use the C# nameof() function to resolve the route name, as it avoids any typos that could produce a runtime error. If you add the <b>Route</b> attribute to a Shell object as a string, you may pass this string to the GoToAsync() method as well.</p> <p id="72">Modify the Shell to call this new page instead of the user detail page you created earlier. Open the <b>AppShell.xaml</b> file and modify the <ShellContent> element that used to call the UserDetailView page and replace it with a call to the UserListView page, as shown in the following XAML:</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">ShellContent</font> <font color="Blue">»</font> <font color="Red">Title</font> <font color="Blue">=</font> <font color="#A31515">"Users"</font> </codesnippet> <codesnippet> <font color="Blue">»»</font> <font color="Red">ContentTemplate</font> <font color="Blue">=</font> <font color="#A31515">"{DataTemplate</font> </codesnippet> <codesnippet> <font color="#A31515">»»»»views:UserListView}"</font> <font color="Blue">»/></font> </codesnippet> <h3>Register the Route</h3> <p id="73">All of the ShellContent objects in the AppShell.xaml file create a global route table that .NET MAUI uses to navigate to each page. Because you removed the <b>UserDetailView</b> ShellContent object, it’s now no longer a part of this global route table. If you tried to run the application right now and clicked on the <b>Navigate to Detail</b> button, you’d receive a runtime error that the route does not exist. Instead of using XAML to create the route table, you may add as many other routes as you need using C#. Open the <b>AppShell.xaml.cs</b> file and in the constructor register the route to the UserDetailView page using the following code:</p> <codesnippet> <font color="Blue">public</font> <font>»</font> <font color="#A31515">AppShell</font> <font>()</font> <font>»</font>{</codesnippet> <codesnippet>»»InitializeComponent();</codesnippet> <codesnippet> <font color="Green">»»//»Register»route</font> <font color="Green">s</font> </codesnippet> <codesnippet>»»Routing.RegisterRoute(</codesnippet> <codesnippet>»»»<font color="Blue">nameof</font>(Views.UserDetailView),</codesnippet> <codesnippet>»»»<font color="Blue">typeof</font>(Views.UserDetailView));</codesnippet> <codesnippet>}</codesnippet> <p id="74">The above code adds the name of the UserDetailView page, and the C# type of UserDetailView to the global route table. Now the routing engine knows which page to display when you request the route name of UserDetailView.</p> <h3>Try It Out</h3> <p id="75">Restart the application and click on the <b>Users</b> menu. Click on the <b>Navigate to Detail</b> button and you should see the <b>User Information</b> page appear.</p> <h2>Create Reusable UI</h2> <p id="76">One of the basic tenets of programming is that you should only write code once, then reuse it as many times as you want. This applies when designing your UI as well. On the user detail view page, the first three rows would be nice to have on all of the pages, so each looks consistent. The first row is a short title to uniquely identify the page. The second row is a short description to describe what this page is used for. The third row is a line to separate the header information from the unique details on the page. Of course, the title and short description should be able to be modified from each page on which these two labels are placed.</p> <p id="77">To create a custom reusable view onto which you can place any controls and then have those controls appear on any other page, use a <b>ContentView</b> control. The ContentView control is a container onto which you place as many controls as you want. You then place the ContentView control onto the page(s) you wish to use that group of controls.</p> <h3>Create a Header View</h3> <p id="78">Let's create a custom "header" view onto which you can place the two labels and the box view control you used on the user detail view page. Right mouse-click on the project and add a new folder named <b>ViewsPartial</b>. Right mouse-click on the <b>ViewsPartial</b> folder and select <b>Add > New Item > .NET MAUI > .NET MAUI ContentView (XAML)…</b> from the context-sensitive menu. Set the name of the ContentView to <b>HeaderView</b>. Add to the <ContentView> starting tag an <b>x:Name</b> attribute, as shown below, so you may reference the ContentView control named HeaderView by using the name "header".</p> <codesnippet>x:Name="header"</codesnippet> <p id="79">Replace the <VerticalStackLayout> element of this new file with the XAML shown in <b>Listing 4</b>. </p> <h3>The Basics of Data Binding</h3> <p id="80">There are a few pieces of this code that need a little explanation as you’re now using data binding. Data binding is a powerful tool that helps you eliminate C# code to control how data is shared between different objects. In the code in<b> </b><b /><b> REF _Ref164078564 \h \* MERGEFORMAT </b><b /><b /><b>Listing 4</b><b />, two Label controls have been placed onto this ContentView control and their <b>Text</b> property has been set to a markup extension called <b>Binding</b>. This Binding class has a <b>Path</b> property to which you set the name of a property on your ContentView control. You’re going to create two C# properties in the code-behind of this HeaderView control named <b>ViewTitle</b> and <b>ViewDescription</b>. There is also a <b>FallbackValue</b> property on the Binding class to which you specify a default value if the property being bound to is null or empty.</p> <p id="81">For the Binding class to know where the property is located, a <b>BindingContext</b> must be set either on the Label controls or on one its parent controls. If you look at the Grid control (which is the parent of the Label controls) you see that the <b>BindingContext</b> property is set on this control. This <b>BindingContext</b> property is set the markup extension <b>x:Reference</b>, which references the <b>x:Name</b> attribute that has been set on the ContentView control. By referencing the ContentView control using the name, it identifies the HeaderView class is the object that has the properties to reference.</p> <h3>Create Bindable Properties</h3> <p id="82">You now need to create the <b>ViewTitle</b> and <b>ViewDescription</b> properties on the HeaderView class. You can't just create normal C# properties with simple getters and setters. A <b>BindableProperty</b> object is used to create the backing fields for both the properties. By using a BindableProperty object, the UI is automatically notified when a property value changes. Open the <b>ViewsPartial\HeaderView.xaml.cs</b> file and add two bindable properties just below the constructor, as shown in <b>Listing 5</b>.</p> <h3>Add Header to the User Detail View</h3> <p id="83">Now that you have your reusable header view, it’s time to add it to the different pages. Open the <b>Views\UserDetailView.xaml</b> file and add the following XML namespace within the <ContentPage>.</p> <codesnippet>xmlns:partial="clr-namespace:AdventureWorks</codesnippet> <codesnippet>»».MAUI.ViewsPartial"</codesnippet> <p id="84">Delete the first two Label controls and the BoxView control within the Grid and replace those controls with the following XAML. You’re adding a reference to the HeaderView control located in the namespace aliased by <b>partial</b>. Because the <b>ViewTitle</b> and <b>ViewDescription</b> are public properties, you can set these properties on this control. Be sure that the quoted string for ViewDescription is only on a single line when you type this code into Visual Studio.</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">partial:HeaderView</font> <font color="Blue">»</font> <font color="Red">Grid.Row</font> <font color="Blue">=</font> <font color="#A31515">"0"</font> </codesnippet> <codesnippet> <font color="Blue">»»</font> <font color="Red">Grid.ColumnSpan</font> <font color="Blue">=</font> <font color="#A31515">"2"</font> </codesnippet> <codesnippet> <font color="Blue">»»</font> <font color="Red">ViewTitle</font> <font color="Blue">=</font> <font color="#A31515">"User»Information"</font> </codesnippet> <codesnippet> <font color="Blue">»»</font> <font color="Red">ViewDescription</font> <font color="Blue">=</font> <font color="#A31515">"Use»this»screen»to»</font> </codesnippet> <codesnippet> <font color="#A31515">»»»»»modify»user»information."</font> <font color="Blue">»/></font> </codesnippet> <p id="85">You deleted three rows from the Grid control on this page and only replaced one row, so remove two "Auto" values from the <b>RowDefinitions</b> property on the Grid. You now also need to renumber the remaining rows in the <Grid> by reducing each by two (2). Go ahead and renumber all the rows now.</p> <h3>Try It Out</h3> <p id="86">Run the application and click on <b>Users > Navigate to Detail</b> to view this page with the new reusable header. Notice that the <b>ViewTitle</b> and <b>ViewDescription</b> properties are set to the values you used in the XAML you just typed in.</p> <h3>Add a Header to the Login View</h3> <p id="87">Open the <b>Views\LoginView.xaml</b> file and add the following XML namespace as an attribute on the <ContentPage> element:</p> <codesnippet>xmlns:partial="clr-namespace:AdventureWorks</codesnippet> <codesnippet>»».MAUI.ViewsPartial"</codesnippet> <p id="88">Delete the <Label> element that is currently in this ContentPage and add the XAML shown in <b>Listing 6</b> where the <Label> was. Notice that the <b>ViewTitle</b> and <b>ViewDescription</b> properties are set to different values than those you used on the user detail view page. Also notice the use of the <b>IsPassword</b> property on the second Entry control. Setting this property ensures that no one can see the password as you are typing into this control.</p> <h3>Try It Out</h3> <p id="89">Run the application and click on the <b>Login</b> menu to view this page. You should see the reusable header above the other controls on this page.</p> <h3>Add a Header to the Product Detail View</h3> <p id="90">Open the <b>Views\ProductDetailView.xaml</b> file and add the following XML namespace as an attribute on the <ContentPage> element.</p> <codesnippet>xmlns:partial="clr-namespace:AdventureWorks</codesnippet> <codesnippet>»».MAUI.ViewsPartial"</codesnippet> <p id="91">Delete the <Label> element that is currently in this ContentPage and add the XAML shown in <b>Listing 7</b> where the <Label> was.</p> <h3>Try It Out</h3> <p id="92">Run the application and click on the <b>Products</b> menu to view this page with the reusable header and the various controls. Don't worry if some of the controls are cropped off at the bottom of the window. You’ll fix this later.</p> <h2>Add a Border on All Pages</h2> <p id="93">A <b>Border</b> control allows you to draw any size border around a control, or a set of controls. Use the <b>StrokeThickness</b> property to set the size in device-independent pixels. The default size is one pixel. The <b>Stroke</b> property sets the color for the border outline. The default color is light gray. Open the <b>MainPage.xaml</b> file and replace the <Label> element with the following XAML to draw a border around the label on the main page.</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">Border</font> <font color="Blue">»</font> <font color="Red">StrokeThickness</font> <font color="Blue">=</font> <font color="#A31515">"2"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»»</font> <font color="Red">HorizontalOptions</font> <font color="Blue">=</font> <font color="#A31515">"Center"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»»</font> <font color="Red">VerticalOptions</font> <font color="Blue">=</font> <font color="#A31515">"Center"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»»</font> <font color="Red">Padding</font> <font color="Blue">=</font> <font color="#A31515">"10"</font> <font color="Blue">></font> </codesnippet> <codesnippet>»»<font color="Blue"><</font><font color="Blue">Label</font><font color="Blue">»</font><font color="Red">Text</font><font color="Blue">=</font><font color="#A31515">"{StaticResource»ApplicationTitle}"</font></codesnippet> <codesnippet> <font color="Blue">»»»»»»»»»</font> <font color="Red">FontSize</font> <font color="Blue">=</font> <font color="#A31515">"Large"</font> <font color="Blue">»/></font> </codesnippet> <codesnippet> <font color="Blue"></</font> <font color="Blue">Border</font> <font color="Blue">></font> </codesnippet> <h3>Try It Out</h3> <p id="94">Run the application and see the border around the application title on the main page.</p> <h3>Create a Keyed Border Style</h3> <p id="95">I like to wrap a border around each of my pages to make it stand out a little from the edges of the window on which it’s hosted. Wrap a Border control around all grids on each page by creating a keyed style to define the standard look for the border on each page. Open the <b>Resources\Styles\CommonStyles.xaml</b> file in the <b>Common.Library.MAUI</b> project and add the keyed style named <b>Border.Page</b> as shown in the XAML below:</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">Style</font> <font color="Blue">»</font> <font color="Red">TargetType</font> <font color="Blue">=</font> <font color="#A31515">"Border"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»</font> <font color="Red">x:Key</font> <font color="Blue">=</font> <font color="#A31515">"Border.Page"</font> <font color="Blue">></font> </codesnippet> <codesnippet> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"Stroke"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"Gray"</font> <font color="Blue">»/></font> </codesnippet> <codesnippet> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"StrokeThickness"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"1"</font> <font color="Blue">»/></font> </codesnippet> <codesnippet> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"Margin"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"10"</font> <font color="Blue">»/></font> </codesnippet> <codesnippet> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"HorizontalOptions"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"Fill"</font> <font color="Blue">»/></font> </codesnippet> <codesnippet> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"VerticalOptions"</font> </codesnippet> <codesnippet> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"Fill"</font> <font color="Blue">»/></font> </codesnippet> <codesnippet> <font color="Blue"></</font> <font color="Blue">Style</font> <font color="Blue">></font> </codesnippet> <p id="96">Let's now apply this keyed border style on a Border control that you wrap around each Grid control on each of your pages. Open the <b>Views\LoginView.xaml</b> file and wrap a <Border> element around the Grid control. Don't forget to add a closing </Border> tag just after the closing </Grid> tag. Add the <b>Style</b> attribute to the border and reference the Border.Page keyed style.</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">Border</font> <font color="Blue">»</font> <font color="Red">Style</font> <font color="Blue">=</font> <font color="#A31515">"{StaticResource»Border.Page}"</font> <font color="Blue">></font> </codesnippet> <codesnippet>»»<font color="Blue"><</font><font color="Blue">Grid</font><font color="Blue">»</font><font color="Red">...</font><font color="Blue">></font></codesnippet> <codesnippet>»»»»<font color="#A31515">//»REST»OF»THE»XAML»HERE</font></codesnippet> <codesnippet>»»<font color="Blue"></</font><font color="Blue">Grid</font><font color="Blue">></font></codesnippet> <codesnippet> <font color="Blue"></</font> <font color="Blue">Border</font> <font color="Blue">></font> </codesnippet> <p id="97">Open the <b>Views\ProductDetail.xaml</b> file and wrap a <Border> around the Grid control using the keyed style Border.Page.</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">Border</font> <font color="Blue">»</font> <font color="Red">Style</font> <font color="Blue">=</font> <font color="#A31515">"{StaticResource»Border.Page}"</font> <font color="Blue">></font> </codesnippet> <codesnippet>»»<font color="Blue"><</font><font color="Blue">Grid</font><font color="Blue">»</font><font color="Red">...</font><font color="Blue">></font></codesnippet> <codesnippet>»»»»<font color="#A31515">//»REST»OF»THE»XAML»HERE</font></codesnippet> <codesnippet>»»<font color="Blue"></</font><font color="Blue">Grid</font><font color="Blue">></font></codesnippet> <codesnippet> <font color="Blue"></</font> <font color="Blue">Border</font> <font color="Blue">></font> </codesnippet> <p id="98">Open the <b>Views\UserDetailView.xaml</b> file and wrap a <Border> around the Grid control using the keyed style Border.Page.</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">Border</font> <font color="Blue">»</font> <font color="Red">Style</font> <font color="Blue">=</font> <font color="#A31515">"{StaticResource»Border.Page}"</font> <font color="Blue">></font> </codesnippet> <codesnippet>»»<font color="Blue"><</font><font color="Blue">Grid</font><font color="Blue">»</font><font color="Red">...</font><font color="Blue">></font></codesnippet> <codesnippet>»»»»<font color="#A31515">//»REST»OF»THE»XAML»HERE</font></codesnippet> <codesnippet>»»<font color="Blue"></</font><font color="Blue">Grid</font><font color="Blue">></font></codesnippet> <codesnippet> <font color="Blue"></</font> <font color="Blue">Border</font> <font color="Blue">></font> </codesnippet> <h3>Try It Out</h3> <p id="99">Run the application and click on each menu item of the changed files to view the border around each screen.</p> <h2>Add a ScrollView to all Pages</h2> <p id="100">With the application running, click on the <b>Products</b> menu and reduce the main window to show how the controls on the bottom of the page are cropped. Because you never know what the screen size is going to be that the user is running on, it’s a good idea to wrap your controls on a page within a scrollable area. This is accomplished by using a <b>ScrollView</b> control. Open the <b>Views\ProductDetailView.xaml</b> file and wrap a <ScrollView> element around the <Grid> element as shown in the following XAML:</p> <codesnippet> <font color="Blue"><</font> <font color="Blue">Border</font> <font color="Blue">»</font> <font color="Red">...</font> <font color="Blue">></font> </codesnippet> <codesnippet> <font>»»</font> <font color="Blue"><</font> <font color="Blue">ScrollView</font> <font color="Blue">></font> </codesnippet> <codesnippet>»»»»<font color="Blue"><</font><font color="Blue">Grid</font><font color="Blue">»</font><font color="Red">...</font><font color="Blue">></font></codesnippet> <codesnippet>»»»»<font color="Blue"></</font><font color="Blue">Grid</font><font color="Blue">></font></codesnippet> <codesnippet> <font>»»</font> <font color="Blue"></</font> <font color="Blue">ScrollView</font> <font color="Blue">></font> </codesnippet> <codesnippet> <font color="Blue"></</font> <font color="Blue">Border</font> <font color="Blue">></font> </codesnippet> <p id="101">Wrap the same <ScrollView> element around the <Grid> element shown in the previous XAML to both the <b>Views\UserDetailView.xaml</b> file and the <b>Views\LoginView.xaml</b> file.</p> <h3>Try It Out</h3> <p id="102">Run the application, click on the <b>Products</b> menu, and reduce the main window size to show that it now displays a scroll bar. Click on the <b>Users menu > Navigate to Detail button</b> and see the scroll bar appear on the User Detail page.</p> <h2>Summary</h2> <p id="103">In this article, you used styles to make all pages in your application look consistent. Styles may be placed at many different locations. Which location you choose determines how reusable those styles are. Several pages were created, and you learned how to use the built-in navigation to move from one page to another. Using a ContentView control when you want to create reusable UI for several (or all) pages in your application. Use data binding to change property values on the ContentView control. </p> <p id="104">Coming up in the next article, you’ll start using the many different input controls and learn which ones should be used for specific input data types. In addition, you’re going to learn much more about data binding. You’ll see how data binding can be used to bind one control to another, and to bind properties in a class to controls on your forms.</p> </body> <sidebars> <sidebar title="Getting the Sample Code"> <p id="105">You can download the sample code for this article by visiting www.CODEMag.com under the issue and article, or by visiting www.pdsa.com/downloads. Select "Articles" from the Category drop-down. Then select "Exploring .NET MAUI: Styles, Navigation, and Reusable UI" from the Item drop-down.</p> </sidebar> </sidebars> <tables /> <codelistings> <codelisting id="1" header="Listing 1: Add a set of Style elements to apply attributes to the same types of controls."> <code> <font color="#2B91AF"><?xml»version=</font> <font color="#A31515">"1.0"</font> <font color="#2B91AF">»encoding=</font> <font color="#A31515">"utf-8"</font> <font color="#2B91AF">»?></font> </code> <code> <font color="Blue"><</font> <font color="Blue">ContentPage</font> <font color="Blue">»</font> <font color="Red">...</font> <font color="Blue">></font> <font>»</font> </code> <code /> <code> <font color="Blue"><</font> <font color="Blue">ContentPage.Resources</font> <font color="Blue">></font> <font>»»»»</font> </code> <code> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Style</font> <font color="Blue">»</font> <font color="Red">TargetType</font> <font color="Blue">=</font> <font color="#A31515">"Grid"</font> <font color="Blue">></font> </code> <code> <font>»»»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"ColumnSpacing"</font> </code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"10"</font> <font color="Blue">»/></font> </code> <code> <font>»»»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"RowSpacing"</font> </code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"10"</font> <font color="Blue">»/></font> </code> <code> <font>»»»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"Margin"</font> </code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"10"</font> <font color="Blue">»/></font> </code> <code> <font>»»»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"Padding"</font> </code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"10"</font> <font color="Blue">»/></font> </code> <code> <font>»»</font> <font color="Blue"></</font> <font color="Blue">Style</font> <font color="Blue">></font> </code> <code>»»<font color="Blue"><</font><font color="Blue">Style</font><font color="Blue">»</font><font color="Red">TargetType</font><font color="Blue">=</font><font color="#A31515">"Label"</font><font color="Blue">></font></code> <code> <font>»»»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"</font> <font color="#A31515">VerticalOptions</font> <font color="#A31515">"</font> </code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"Center"</font> <font color="Blue">»/></font> </code> <code> <font>»»</font> <font color="Blue"></</font> <font color="Blue">Style</font> <font color="Blue">></font> </code> <code>»»<font color="Blue"><</font><font color="Blue">Style</font><font color="Blue">»</font><font color="Red">TargetType</font><font color="Blue">=</font><font color="#A31515">"HorizontalStackLayout"</font><font color="Blue">></font></code> <code> <font>»»»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"Spacing"</font> </code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"5"</font> <font color="Blue">»/></font> </code> <code> <font>»»</font> <font color="Blue"></</font> <font color="Blue">Style</font> <font color="Blue">></font> </code> <code> <font color="Blue"></</font> <font color="Blue">ContentPage.Resources</font> <font color="Blue">></font> </code> <code /> <code> <font color="Blue"><</font> <font color="Blue">Grid</font> <font color="Blue">»</font> <font color="Red">...</font> <font color="Blue">></font> </code> <code /> <code>//»REST»OF»THE»XAML</code> </codelisting> <codelisting id="2" header="Listing 2: Create a resource dictionary file into which you create your custom styles."> <code> <font color="Green"><!--»******************»--></font> </code> <code> <font color="Green"><!--»**»My»Keyed»Styles»--></font> </code> <code> <font color="Green"><!--»******************»--></font> </code> <code> <font color="Blue"><</font> <font color="Blue">Style</font> <font color="Blue">»</font> <font color="Red">TargetType</font> <font color="Blue">=</font> <font color="#A31515">"Grid"</font> </code> <code> <font color="Blue">»»»»»»»»</font> <font color="Red">x:Key</font> <font color="Blue">=</font> <font color="#A31515">"Grid.Page"</font> <font color="Blue">></font> </code> <code> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"ColumnSpacing"</font> </code> <code> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"10"</font> <font color="Blue">»/></font> </code> <code> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"RowSpacing"</font> </code> <code> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"10"</font> <font color="Blue">»/></font> </code> <code> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"Margin"</font> </code> <code> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"10"</font> <font color="Blue">»/></font> </code> <code> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"Padding"</font> </code> <code> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"10"</font> <font color="Blue">»/></font> </code> <code> <font color="Blue"></</font> <font color="Blue">Style</font> <font color="Blue">></font> </code> <code> <font color="Blue"><</font> <font color="Blue">Style</font> <font color="Blue">»</font> <font color="Red">TargetType</font> <font color="Blue">=</font> <font color="#A31515">"Element"</font> </code> <code> <font color="Blue">»»»»»»»</font> <font color="Red">x:Key</font> <font color="Blue">=</font> <font color="#A31515">"ShellStyles"</font> <font color="Blue">></font> </code> <code> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"Shell.BackgroundColor"</font> </code> <code> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"Blue"</font> <font color="Blue">»/></font> </code> <code> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"Shell.TitleColor"</font> </code> <code> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"White"</font> <font color="Blue">»/></font> </code> <code> <font color="Blue"></</font> <font color="Blue">Style</font> <font color="Blue">></font> </code> <code /> <code> <font color="Green"><!--»*************»--></font> </code> <code> <font color="Green"><!--»Global»Styles»--></font> </code> <code> <font color="Green"><!--»*************»--></font>»»</code> <code> <font color="Blue"><</font> <font color="Blue">Style</font> <font color="Blue">»</font> <font color="Red">TargetType</font> <font color="Blue">=</font> <font color="#A31515">"Label"</font> <font color="Blue">></font> </code> <code> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"</font> <font color="#A31515">VerticalOptions</font> <font color="#A31515">"</font> </code> <code> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"Center"</font> <font color="Blue">»/></font> </code> <code> <font color="Blue"></</font> <font color="Blue">Style</font> <font color="Blue">></font> </code> <code> <font color="Blue"><</font> <font color="Blue">Style</font> <font color="Blue">»</font> <font color="Red">TargetType</font> <font color="Blue">=</font> <font color="#A31515">"HorizontalStackLayout"</font> <font color="Blue">></font> </code> <code> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"Spacing"</font> </code> <code> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"5"</font> <font color="Blue">»/></font> </code> <code> <font color="Blue"></</font> <font color="Blue">Style</font> <font color="Blue">></font> </code> </codelisting> <codelisting id="3" header="Listing 3: Move resources and styles into the common MAUI library resource dictionary."> <code> <font color="Green"><!--»***************»--></font> </code> <code> <font color="Green"><!--»Other»Resources»--></font> </code> <code> <font color="Green"><!--»***************»--></font> </code> <code> <font color="Blue"><</font> <font color="Blue">x:Double</font> <font color="Blue">»</font> <font color="Red">x:Key</font> <font color="Blue">=</font> <font color="#A31515">"DefaultSpacingForGrid"</font> <font color="Blue">></font> </code> <code>»»10</code> <code> <font color="Blue"></</font> <font color="Blue">x:Double</font> <font color="Blue">></font> </code> <code /> <code> <font color="Green"><!--»******************»--></font> </code> <code> <font color="Green"><!--»**»My»Keyed»Styles»--></font> </code> <code> <font color="Green"><!--»******************»--></font> </code> <code> <font color="Blue"><</font> <font color="Blue">Style</font> <font color="Blue">»</font> <font color="Red">TargetType</font> <font color="Blue">=</font> <font color="#A31515">"Grid"</font> </code> <code> <font color="Blue">»»»»»»»</font> <font color="Red">x:Key</font> <font color="Blue">=</font> <font color="#A31515">"Grid.Page"</font> <font color="Blue">></font> </code> <code> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"ColumnSpacing"</font> </code> <code> <font color="Blue">»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"{StaticResource</font> </code> <code> <font color="#A31515">»»»»»»DefaultSpacingForGrid}"</font> <font color="Blue">»/></font> </code> <code> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"RowSpacing"</font> </code> <code> <font color="Blue">»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"{StaticResource</font> </code> <code> <font color="#A31515">»»»»»»DefaultSpacingForGrid}"</font> <font color="Blue">»/></font> </code> <code> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"Margin"</font> </code> <code> <font color="Blue">»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"{StaticResource</font> </code> <code> <font color="#A31515">»»»»»»DefaultSpacingForGrid}"</font> <font color="Blue">»/></font> </code> <code> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"Padding"</font> </code> <code> <font color="Blue">»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"{StaticResource</font> </code> <code> <font color="#A31515">»»»»»»DefaultSpacingForGrid}"</font> <font color="Blue">»/></font> </code> <code> <font color="Blue"></</font> <font color="Blue">Style</font> <font color="Blue">></font> </code> <code> <font color="Blue"><</font> <font color="Blue">Style</font> <font color="Blue">»</font> <font color="Red">TargetType</font> <font color="Blue">=</font> <font color="#A31515">"Element"</font> </code> <code> <font color="Blue">»»»»»»»</font> <font color="Red">x:Key</font> <font color="Blue">=</font> <font color="#A31515">"ShellStyles"</font> <font color="Blue">></font> </code> <code> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"Shell.BackgroundColor"</font> </code> <code> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"Blue"</font> <font color="Blue">»/></font> </code> <code> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"Shell.TitleColor"</font> </code> <code> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"White"</font> <font color="Blue">»/></font> </code> <code> <font color="Blue"></</font> <font color="Blue">Style</font> <font color="Blue">></font> </code> <code /> <code> <font color="Green"><!--»*************»--></font> </code> <code> <font color="Green"><!--»Global»Styles»--></font> </code> <code> <font color="Green"><!--»*************»--></font> </code> <code> <font color="Blue"><</font> <font color="Blue">Style</font> <font color="Blue">»</font> <font color="Red">TargetType</font> <font color="Blue">=</font> <font color="#A31515">"Label"</font> <font color="Blue">></font> </code> <code> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"</font> <font color="#A31515">VerticalOptions</font> <font color="#A31515">"</font> </code> <code> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"Center"</font> <font color="Blue">»/></font> </code> <code> <font color="Blue"></</font> <font color="Blue">Style</font> <font color="Blue">></font> </code> <code> <font color="Blue"><</font> <font color="Blue">Style</font> <font color="Blue">»</font> <font color="Red">TargetType</font> <font color="Blue">=</font> <font color="#A31515">"HorizontalStackLayout"</font> <font color="Blue">></font> </code> <code> <font>»»</font> <font color="Blue"><</font> <font color="Blue">Setter</font> <font color="Blue">»</font> <font color="Red">Property</font> <font color="Blue">=</font> <font color="#A31515">"Spacing"</font> </code> <code> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Value</font> <font color="Blue">=</font> <font color="#A31515">"5"</font> <font color="Blue">»/></font> </code> <code> <font color="Blue"></</font> <font color="Blue">Style</font> <font color="Blue">></font> </code> </codelisting> <codelisting id="4" header="Listing 4: Create a reusable header view that can be placed onto many pages."> <code> <font color="Blue"><</font> <font color="Blue">Grid</font> <font color="Blue">»</font> <font color="Red">BindingContext</font> <font color="Blue">=</font> <font color="#A31515">"{x:Reference»header}"</font> </code> <code> <font color="Blue">»»»»»»</font> <font color="Red">RowDefinitions</font> <font color="Blue">=</font> <font color="#A31515">"Auto,Auto,Auto"</font> <font color="Blue">></font> </code> <code>»»<font color="Blue"><</font><font color="Blue">Label</font><font color="Blue">»</font><font color="Red">Grid.Row</font><font color="Blue">=</font><font color="#A31515">"0"</font></code> <code> <font color="Blue">»»»»»»»»»</font> <font color="Red">Text</font> <font color="Blue">=</font> <font color="#A31515">"{Binding»Path=ViewTitle,</font> </code> <code> <font color="#A31515">»»»»»»»»»»»FallbackValue='View»Title'}"</font> </code> <code> <font color="Blue">»»»»»»»»»</font> <font color="Red">HorizontalOptions</font> <font color="Blue">=</font> <font color="#A31515">"Center"</font> </code> <code> <font color="Blue">»»»»»»»»»»</font> <font color="Red">FontSize</font> <font color="Blue">=</font> <font color="#A31515">"Title"</font> <font color="Blue">»/></font> </code> <code>»»<font color="Blue"><</font><font color="Blue">Label</font><font color="Blue">»</font><font color="Red">Grid.Row</font><font color="Blue">=</font><font color="#A31515">"1"</font></code> <code> <font color="Blue">»</font> <font color="Blue">»»»»»»»»</font> <font color="Red">Grid.ColumnSpan</font> <font color="Blue">=</font> <font color="#A31515">"2"</font> </code> <code> <font color="Blue">»»»»»»»»»</font> <font color="Red">Text</font> <font color="Blue">=</font> <font color="#A31515">"{Binding»Path=ViewDescription,</font> </code> <code> <font color="#A31515">»»»»»»»»»»»»FallbackValue='View»Description'}"</font> </code> <code> <font color="Blue">»»»»»»»»»</font> <font color="Red">HorizontalOptions</font> <font color="Blue">=</font> <font color="#A31515">"Center"</font> </code> <code> <font color="Blue">»»»»»»»»»</font> <font color="Red">FontSize</font> <font color="Blue">=</font> <font color="#A31515">"Body"</font> <font color="Blue">»/></font> </code> <code>»»<font color="Blue"><</font><font color="Blue">BoxView</font><font color="Blue">»</font><font color="Red">Grid.Row</font><font color="Blue">=</font><font color="#A31515">"2"</font></code> <code> <font color="Blue">»»»»»»»»»»»</font> <font color="Red">HeightRequest</font> <font color="Blue">=</font> <font color="#A31515">"1"</font> </code> <code> <font color="Blue">»»»»»»»»»»»</font> <font color="Red">Color</font> <font color="Blue">=</font> <font color="#A31515">"Black"</font> <font color="Blue">»/></font> </code> <code>»<font color="Blue"></</font><font color="Blue">Grid</font><font color="Blue">></font></code> </codelisting> <codelisting id="5" header="Listing 5: Connect UI label text with data set into the bindable properties."> <code> <font color="Blue">public</font>»<font color="Blue">string</font>»ViewTitle»{</code> <code> <font color="Blue">»»</font> <font color="Blue">get</font>»{»</code> <code>»»»»<font color="Blue">return</font>»(<font color="Blue">string</font>)GetValue(ViewTitleProperty);»</code> <code>»»}</code> <code>»»<font color="Blue">set</font>»{</code> <code>»»»»SetValue(ViewTitleProperty,»<font color="Blue">value</font>);»</code> <code>»»}</code> <code>}</code> <code /> <code> <font color="Blue">public</font>»<font color="Blue">static</font>»<font color="Blue">readonly</font>»BindableProperty</code> <code>»»ViewTitleProperty»=</code> <code>»»»»BindableProperty.Create(<font color="#A31515">"ViewTitle"</font>,</code> <code>»»»»»»<font color="Blue">typeof</font>(<font color="Blue">string</font>),»<font color="Blue">typeof</font>(HeaderView),»</code> <code>»»»»»»<font color="Blue">string</font>.Empty);</code> <code /> <code> <font color="Blue">public</font>»<font color="Blue">string</font>»ViewDescription»{</code> <code>»»<font color="Blue">get</font>»{»</code> <code>»»»»<font color="Blue">return</font>»(<font color="Blue">string</font>)GetValue(</code> <code>»»»»»»ViewDescriptionProperty);»</code> <code>»»}</code> <code>»»<font color="Blue">set</font>»{»</code> <code>»»»»SetValue(ViewDescriptionProperty,»<font color="Blue">value</font>);</code> <code>»»}</code> <code>}</code> <code /> <code> <font color="Blue">public</font>»<font color="Blue">static</font>»<font color="Blue">readonly</font>»BindableProperty</code> <code>»»ViewDescriptionProperty»=</code> <code>»»»»BindableProperty.Create(<font color="#A31515">"ViewDescription"</font>,</code> <code>»»»»»»<font color="Blue">typeof</font>(<font color="Blue">string</font>),»<font color="Blue">typeof</font>(HeaderView),</code> <code>»»»»»»<font color="Blue">string</font>.Empty);</code> </codelisting> <codelisting id="6" header="Listing 6: Use the header view partial page on all pages for a consistent look and feel."> <code> <font color="Blue"><</font> <font color="Blue">Grid</font> <font color="Blue">»</font> <font color="Red">RowDefinitions</font> <font color="Blue">=</font> <font color="#A31515">"Auto,Auto,Auto,Auto"</font> </code> <code> <font color="Blue">»»»»»»</font> <font color="Red">ColumnDefinitions</font> <font color="Blue">=</font> <font color="#A31515">"Auto,*"</font> </code> <code> <font color="Blue">»»»»»»</font> <font color="Red">Style</font> <font color="Blue">=</font> <font color="#A31515">"{StaticResource»Grid.Page}"</font> <font color="Blue">></font> </code> <code /> <code>»»<font color="Blue"><</font><font color="Blue">partial:HeaderView</font><font color="Blue">»</font><font color="Red">Grid.Row</font><font color="Blue">=</font><font color="#A31515">"0"</font></code> <code> <font color="Blue">»»»»»»</font> <font color="Red">Grid.ColumnSpan</font> <font color="Blue">=</font> <font color="#A31515">"2"</font> </code> <code> <font color="Blue">»»»»»»</font> <font color="Red">ViewTitle</font> <font color="Blue">=</font> <font color="#A31515">"Login"</font> </code> <code> <font color="Blue">»»»»»»</font> <font color="Red">ViewDescription</font> <font color="Blue">=</font> <font color="#A31515">"Use»this»screen»to»</font> </code> <code> <font color="#A31515">»»»»»»»»login»to»this»application."</font> <font color="Blue">»»/></font> </code> <code /> <code>»»<font color="Blue"><</font><font color="Blue">Label</font><font color="Blue">»</font><font color="Red">Grid.Row</font><font color="Blue">=</font><font color="#A31515">"1"</font></code> <code> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Text</font> <font color="Blue">=</font> <font color="#A31515">"Login»ID"</font> <font color="Blue">»/></font> </code> <code>»»<font color="Blue"><</font><font color="Blue">Entry</font><font color="Blue">»</font><font color="Red">Grid.Row</font><font color="Blue">=</font><font color="#A31515">"1"</font></code> <code> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Grid.Column</font> <font color="Blue">=</font> <font color="#A31515">"1"</font> </code> <code> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Text</font> <font color="Blue">=</font> <font color="#A31515">""</font> <font color="Blue">»/></font> </code> <code>»»<font color="Blue"><</font><font color="Blue">Label</font><font color="Blue">»</font><font color="Red">Grid.Row</font><font color="Blue">=</font><font color="#A31515">"2"</font></code> <code> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Text</font> <font color="Blue">=</font> <font color="#A31515">"Password"</font> <font color="Blue">»/></font> </code> <code>»»<font color="Blue"><</font><font color="Blue">Entry</font><font color="Blue">»</font><font color="Red">Grid.Row</font><font color="Blue">=</font><font color="#A31515">"2"</font></code> <code> <font color="Blue">»»»»»»»»»»</font> <font color="Red">Grid.Column</font> <font color="Blue">=</font> <font color="#A31515">"1"</font> </code> <code> <font color="Blue">»»»»»»»»»»</font> <font color="Red">IsPassword</font> <font color="Blue">=</font> <font color="#A31515">"True"</font> <font color="Blue">»/></font> </code> <code>»»<font color="Blue"><</font><font color="Blue">HorizontalStackLayout</font><font color="Blue">»</font><font color="Red">Grid.Row</font><font color="Blue">=</font><font color="#A31515">"3"</font></code> <code> <font color="Blue">»»»»»»»»»»»»»»»»»»»»»»»»»»</font> <font color="Red">Grid.Column</font> <font color="Blue">=</font> <font color="#A31515">"1"</font> <font color="Blue">></font> </code> <code>»»»»<font color="Blue"><</font><font color="Blue">Button</font><font color="Blue">»</font><font color="Red">Text</font><font color="Blue">=</font><font color="#A31515">"Login"</font><font color="Blue">»/></font></code> <code>»»»»<font color="Blue"><</font><font color="Blue">Button</font><font color="Blue">»</font><font color="Red">Text</font><font color="Blue">=</font><font color="#A31515">"Cancel"</font><font color="Blue">»/></font></code> <code>»»<font color="Blue"></</font><font color="Blue">HorizontalStackLayout</font><font color="Blue">></font></code> <code> <font color="Blue"></</font> <font color="Blue">Grid</font> <font color="Blue">></font> </code> <code /> </codelisting> <codelisting id="7" header="Listing 7 Create the product detail view with many label and entry controls."> <code> <font color="Blue"><</font> <font color="Blue">Grid</font> <font color="Blue">»</font> <font color="Red">RowDefinitions</font> <font color="Blue">=</font> <font color="#A31515">"Auto,Auto,Auto,Auto,</font> </code> <code> <font color="#A31515">»»Auto,Auto,Auto,Auto,Auto,Auto,Auto,</font> </code> <code> <font color="#A31515">»»Auto,Auto,Auto"</font> <font color="Blue">»</font> </code> <code> <font color="Blue">»»»»»»</font> <font color="Red">ColumnDefinitions</font> <font color="Blue">=</font> <font color="#A31515">"Auto,*"</font> </code> <code> <font color="Blue">»»»»»»</font> <font color="Red">Style</font> <font color="Blue">=</font> <font color="#A31515">"{StaticResource»Grid.Page}"</font> <font color="Blue">></font> </code> <code /> <code>»»»»<font color="Blue"><</font><font color="Blue">partial:HeaderView</font><font color="Blue">»</font><font color="Red">Grid.Row</font><font color="Blue">=</font><font color="#A31515">"0"</font></code> <code> <font color="Blue">»»»»»»</font> <font color="Red">Grid.ColumnSpan</font> <font color="Blue">=</font> <font color="#A31515">"2"</font> </code> <code> <font color="Blue">»»»»»»</font> <font color="Red">ViewTitle</font> <font color="Blue">=</font> <font color="#A31515">"Product»Information"</font> </code> <code> <font color="Blue">»»»»»»</font> <font color="Red">ViewDescription</font> <font color="Blue">=</font> <font color="#A31515">"Use»this»screen»to»</font> </code> <code> <font color="#A31515">»»»»»»»»»modify»product»information."</font> <font color="Blue">»»/></font> </code> <code /> <code>»»»»<font color="Blue"><</font><font color="Blue">Label</font><font color="Blue">»</font><font color="Red">Text</font><font color="Blue">=</font><font color="#A31515">"Product»Name"</font></code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Grid.Row</font> <font color="Blue">=</font> <font color="#A31515">"1"</font> <font color="Blue">»/></font> </code> <code>»»»»<font color="Blue"><</font><font color="Blue">Entry</font><font color="Blue">»</font><font color="Red">Grid.Column</font><font color="Blue">=</font><font color="#A31515">"1"</font></code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Grid.Row</font> <font color="Blue">=</font> <font color="#A31515">"1"</font> <font color="Blue">»/></font> </code> <code>»»»»<font color="Blue"><</font><font color="Blue">Label</font><font color="Blue">»</font><font color="Red">Text</font><font color="Blue">=</font><font color="#A31515">"Product»Number"</font></code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Grid.Row</font> <font color="Blue">=</font> <font color="#A31515">"2"</font> <font color="Blue">»/></font> </code> <code>»»»»<font color="Blue"><</font><font color="Blue">Entry</font><font color="Blue">»</font><font color="Red">Grid.Row</font><font color="Blue">=</font><font color="#A31515">"2"</font></code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Grid.Column</font> <font color="Blue">=</font> <font color="#A31515">"1"</font> <font color="Blue">»/></font> </code> <code>»»»»<font color="Blue"><</font><font color="Blue">Label</font><font color="Blue">»</font><font color="Red">Text</font><font color="Blue">=</font><font color="#A31515">"Color"</font></code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Grid.Row</font> <font color="Blue">=</font> <font color="#A31515">"3"</font> <font color="Blue">»/></font> </code> <code>»»»»<font color="Blue"><</font><font color="Blue">Entry</font><font color="Blue">»</font><font color="Red">Grid.Row</font><font color="Blue">=</font><font color="#A31515">"3"</font></code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Grid.Column</font> <font color="Blue">=</font> <font color="#A31515">"1"</font> <font color="Blue">»/></font> </code> <code>»»»»<font color="Blue"><</font><font color="Blue">Label</font><font color="Blue">»</font><font color="Red">Text</font><font color="Blue">=</font><font color="#A31515">"Cost"</font></code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Grid.Row</font> <font color="Blue">=</font> <font color="#A31515">"4"</font> <font color="Blue">»/></font> </code> <code>»»»»<font color="Blue"><</font><font color="Blue">Entry</font><font color="Blue">»</font><font color="Red">Grid.Row</font><font color="Blue">=</font><font color="#A31515">"4"</font></code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Grid.Column</font> <font color="Blue">=</font> <font color="#A31515">"1"</font> <font color="Blue">»/></font> </code> <code>»»»»<font color="Blue"><</font><font color="Blue">Label</font><font color="Blue">»</font><font color="Red">Text</font><font color="Blue">=</font><font color="#A31515">"Price"</font></code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Grid.Row</font> <font color="Blue">=</font> <font color="#A31515">"5"</font> <font color="Blue">»/></font> </code> <code>»»»»<font color="Blue"><</font><font color="Blue">Entry</font><font color="Blue">»</font><font color="Red">Grid.Row</font><font color="Blue">=</font><font color="#A31515">"5"</font></code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Grid.Column</font> <font color="Blue">=</font> <font color="#A31515">"1"</font> <font color="Blue">»/></font> </code> <code>»»»»<font color="Blue"><</font><font color="Blue">Label</font><font color="Blue">»</font><font color="Red">Text</font><font color="Blue">=</font><font color="#A31515">"Size"</font></code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Grid.Row</font> <font color="Blue">=</font> <font color="#A31515">"6"</font> <font color="Blue">»/></font> </code> <code>»»»»<font color="Blue"><</font><font color="Blue">Entry</font><font color="Blue">»</font><font color="Red">Grid.Row</font><font color="Blue">=</font><font color="#A31515">"6"</font></code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Grid.Column</font> <font color="Blue">=</font> <font color="#A31515">"1"</font> <font color="Blue">»/></font> </code> <code>»»»»<font color="Blue"><</font><font color="Blue">Label</font><font color="Blue">»</font><font color="Red">Text</font><font color="Blue">=</font><font color="#A31515">"Weight"</font></code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Grid.Row</font> <font color="Blue">=</font> <font color="#A31515">"7"</font> <font color="Blue">»/></font> </code> <code>»»»»<font color="Blue"><</font><font color="Blue">Entry</font><font color="Blue">»</font><font color="Red">Grid.Row</font><font color="Blue">=</font><font color="#A31515">"7"</font></code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Grid.Column</font> <font color="Blue">=</font> <font color="#A31515">"1"</font> <font color="Blue">»/></font> </code> <code>»»»»<font color="Blue"><</font><font color="Blue">Label</font><font color="Blue">»</font><font color="Red">Text</font><font color="Blue">=</font><font color="#A31515">"Category"</font></code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Grid.Row</font> <font color="Blue">=</font> <font color="#A31515">"8"</font> <font color="Blue">»/></font> </code> <code>»»»»<font color="Blue"><</font><font color="Blue">Entry</font><font color="Blue">»</font><font color="Red">Grid.Row</font><font color="Blue">=</font><font color="#A31515">"8"</font></code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Grid.Column</font> <font color="Blue">=</font> <font color="#A31515">"1"</font> <font color="Blue">»/></font> </code> <code>»»»»<font color="Blue"><</font><font color="Blue">Label</font><font color="Blue">»</font><font color="Red">Text</font><font color="Blue">=</font><font color="#A31515">"Model"</font></code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Grid.Row</font> <font color="Blue">=</font> <font color="#A31515">"9"</font> <font color="Blue">»/></font> </code> <code>»»»»<font color="Blue"><</font><font color="Blue">Entry</font><font color="Blue">»</font><font color="Red">Grid.Row</font><font color="Blue">=</font><font color="#A31515">"9"</font></code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Grid.Column</font> <font color="Blue">=</font> <font color="#A31515">"1"</font> <font color="Blue">»/></font> </code> <code>»»»»<font color="Blue"><</font><font color="Blue">Label</font><font color="Blue">»</font><font color="Red">Text</font><font color="Blue">=</font><font color="#A31515">"Selling»Start»Date"</font></code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Grid.Row</font> <font color="Blue">=</font> <font color="#A31515">"10"</font> <font color="Blue">»/></font> </code> <code>»»»»<font color="Blue"><</font><font color="Blue">Entry</font><font color="Blue">»</font><font color="Red">Grid.Row</font><font color="Blue">=</font><font color="#A31515">"10"</font></code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Grid.Column</font> <font color="Blue">=</font> <font color="#A31515">"1"</font> <font color="Blue">»/></font> </code> <code>»»»»<font color="Blue"><</font><font color="Blue">Label</font><font color="Blue">»</font><font color="Red">Text</font><font color="Blue">=</font><font color="#A31515">"Selling»End»Date"</font></code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Grid.Row</font> <font color="Blue">=</font> <font color="#A31515">"11"</font> <font color="Blue">»/></font> </code> <code>»»»»<font color="Blue"><</font><font color="Blue">Entry</font><font color="Blue">»</font><font color="Red">Grid.Row</font><font color="Blue">=</font><font color="#A31515">"11"</font></code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Grid.Column</font> <font color="Blue">=</font> <font color="#A31515">"1"</font> <font color="Blue">»/></font> </code> <code>»»»»<font color="Blue"><</font><font color="Blue">Label</font><font color="Blue">»</font><font color="Red">Text</font><font color="Blue">=</font><font color="#A31515">"Discontinued»Date"</font></code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Grid.Row</font> <font color="Blue">=</font> <font color="#A31515">"12"</font> <font color="Blue">»/></font> </code> <code>»»»»<font color="Blue"><</font><font color="Blue">Entry</font><font color="Blue">»</font><font color="Red">Grid.Row</font><font color="Blue">=</font><font color="#A31515">"12"</font></code> <code> <font color="Blue">»»»»»»»»»»»»</font> <font color="Red">Grid.Column</font> <font color="Blue">=</font> <font color="#A31515">"1"</font> <font color="Blue">»/></font> </code> <code>»»»»<font color="Blue"><</font><font color="Blue">HorizontalStackLayout</font><font color="Blue">»</font><font color="Red">Grid.Row</font><font color="Blue">=</font><font color="#A31515">"13"</font></code> <code> <font color="Blue">»»»»»»»»»»»»»»»»»»»»»»»»»»»</font> <font color="Red">Grid.Column</font> <font color="Blue">=</font> <font color="#A31515">"1"</font> <font color="Blue">></font> </code> <code>»»»»»»<font color="Blue"><</font><font color="Blue">Button</font><font color="Blue">»</font><font color="Red">Text</font><font color="Blue">=</font><font color="#A31515">"Save"</font><font color="Blue">»/></font></code> <code>»»»»»»<font color="Blue"><</font><font color="Blue">Button</font><font color="Blue">»</font><font color="Red">Text</font><font color="Blue">=</font><font color="#A31515">"Cancel"</font><font color="Blue">»/></font></code> <code>»»»»<font color="Blue"></</font><font color="Blue">HorizontalStackLayout</font><font color="Blue">></font></code> <code> <font color="Blue"></</font> <font color="Blue">Grid</font> <font color="Blue">></font> </code> </codelisting> </codelistings> <Errors> <Error>Sidebar found, but no caption specified. Sidebar cannot be added.</Error> <Error>Sidebar found, but no caption specified. Sidebar cannot be added.</Error> <Error>Sidebar found, but no caption specified. Sidebar cannot be added.</Error> </Errors> </document>