tag:blogger.com,1999:blog-57463148478242448512024-03-13T12:05:51.587-05:00Welcome to my .Net WorldUnknownnoreply@blogger.comBlogger218125tag:blogger.com,1999:blog-5746314847824244851.post-42165182769137766212023-01-26T21:03:00.004-06:002023-02-02T20:04:32.651-06:00LIveCharts2: Charts for Windows and web <p>Charts for Windows and web including .Net MAUI </p><p><a href="https://lvcharts.com/">LiveCharts - LiveCharts2 (lvcharts.com)</a></p><p><br /></p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5746314847824244851.post-9711953445395377232022-12-05T14:18:00.002-06:002022-12-05T14:20:04.434-06:00FIX :ERROR ITMS-90717: "INVALID APP STORE ICON. THE APP STORE ICON IN THE ASSET CATALOG IN '_____' CAN'T BE TRANSPARENT NOR CONTAIN AN ALPHA CHANNEL<p> </p><p style="background: white; vertical-align: baseline;"><span style="color: #3d3d3d; font-family: inherit; font-size: 13.5pt;">When you upload the archive to the
App Store using the tool from Xcode, you may get the following error:<o:p></o:p></span></p>
<table border="0" cellpadding="0" cellspacing="3" class="MsoNormalTable" style="mso-cellspacing: 2.2pt; mso-padding-alt: 0in 0in 0in 0in; mso-yfti-tbllook: 1184;">
<tbody><tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;">
<td style="padding: 0.75pt;">
<p align="center" class="MsoNormal" style="text-align: center; vertical-align: baseline;"><span style="font-family: inherit; font-size: 9pt;">1<o:p></o:p></span></p>
</td>
<td style="box-sizing: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; padding: 0.75pt; width: 812.4pt;" width="1083">
<p class="MsoNormal" style="vertical-align: baseline;"><span class="crayon-e"><span style="border: 1pt none windowtext; color: black; font-family: inherit; font-size: 9pt; mso-border-alt: none windowtext 0in; padding: 0in;">ERROR </span></span><span class="crayon-v"><span style="border: 1pt none windowtext; color: black; font-family: inherit; font-size: 9pt; mso-border-alt: none windowtext 0in; padding: 0in;">ITMS</span></span><span class="crayon-o"><span style="border: 1pt none windowtext; color: black; font-family: inherit; font-size: 9pt; mso-border-alt: none windowtext 0in; padding: 0in;">-</span></span><span class="crayon-cn"><span style="border: 1pt none windowtext; color: black; font-family: inherit; font-size: 9pt; mso-border-alt: none windowtext 0in; padding: 0in;">90717</span></span><span class="crayon-o"><span style="border: 1pt none windowtext; color: black; font-family: inherit; font-size: 9pt; mso-border-alt: none windowtext 0in; padding: 0in;">:</span></span><span class="crayon-h"><span style="border: 1pt none windowtext; color: black; font-family: inherit; font-size: 9pt; mso-border-alt: none windowtext 0in; padding: 0in;">
</span></span><span style="color: black; font-family: inherit; font-size: 9pt;">"<span class="crayon-e"><span style="border: 1pt none windowtext; mso-border-alt: none windowtext 0in; padding: 0in;">Invalid App Store </span></span><span class="crayon-v"><span style="border: 1pt none windowtext; mso-border-alt: none windowtext 0in; padding: 0in;">Icon</span></span><span class="crayon-sy"><span style="border: 1pt none windowtext; mso-border-alt: none windowtext 0in; padding: 0in;">.</span></span><span class="crayon-h"><span style="border: 1pt none windowtext; mso-border-alt: none windowtext 0in; padding: 0in;"> </span></span><span class="crayon-e"><span style="border: 1pt none windowtext; mso-border-alt: none windowtext 0in; padding: 0in;">The App Store Icon </span></span><span class="crayon-st"><span style="border: 1pt none windowtext; mso-border-alt: none windowtext 0in; padding: 0in;">in</span></span><span class="crayon-h"><span style="border: 1pt none windowtext; mso-border-alt: none windowtext 0in; padding: 0in;"> </span></span><span class="crayon-e"><span style="border: 1pt none windowtext; mso-border-alt: none windowtext 0in; padding: 0in;">the asset catalog </span></span><span class="crayon-st"><span style="border: 1pt none windowtext; mso-border-alt: none windowtext 0in; padding: 0in;">in</span></span><span class="crayon-h"><span style="border: 1pt none windowtext; mso-border-alt: none windowtext 0in; padding: 0in;"> </span></span><span class="crayon-s"><span style="border: 1pt none windowtext; mso-border-alt: none windowtext 0in; padding: 0in;">'_____.app'</span></span><span class="crayon-h"><span style="border: 1pt none windowtext; mso-border-alt: none windowtext 0in; padding: 0in;"> </span></span><span class="crayon-i"><span style="border: 1pt none windowtext; mso-border-alt: none windowtext 0in; padding: 0in;">can</span></span>'<span class="crayon-i"><span style="border: 1pt none windowtext; mso-border-alt: none windowtext 0in; padding: 0in;">t</span></span><span class="crayon-h"><span style="border: 1pt none windowtext; mso-border-alt: none windowtext 0in; padding: 0in;"> </span></span><span class="crayon-e"><span style="border: 1pt none windowtext; mso-border-alt: none windowtext 0in; padding: 0in;">be transparent nor contain an alpha </span></span><span class="crayon-v"><span style="border: 1pt none windowtext; mso-border-alt: none windowtext 0in; padding: 0in;">channel</span></span><span class="crayon-sy"><span style="border: 1pt none windowtext; mso-border-alt: none windowtext 0in; padding: 0in;">.</span></span><o:p></o:p></span></p>
</td>
</tr>
</tbody></table>
<p style="background: white; box-sizing: inherit; font-size: 1.125rem; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 2rem; vertical-align: baseline;"><span style="color: #3d3d3d; font-family: inherit; font-size: 13.5pt;">Reason: Your Icon image has feature:
Alpha<o:p></o:p></span></p><p style="background: white; box-sizing: inherit; font-size: 1.125rem; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 2rem; vertical-align: baseline;"><span style="color: #3d3d3d; font-family: inherit; font-size: 13.5pt;">Solution: </span><span face=""Open Sans", "Segoe UI", "Helvetica Neue", Helvetica, Raleway, Arial, sans-serif" style="background-color: #f7f7f9; color: #3a3a3a; font-size: 14px;">Make a PNG without an alpha channel.</span></p>
<p style="background: white; box-sizing: inherit; font-size: 1.125rem; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 2rem; vertical-align: baseline;"><span style="color: #3d3d3d; font-family: inherit; font-size: 13.5pt;">How to fix it:<o:p></o:p></span></p>
<p style="background: white; box-sizing: inherit; font-size: 1.125rem; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0in; vertical-align: baseline;"><span style="color: #3d3d3d; font-family: inherit; font-size: 13.5pt;">Open file: Assets.xcassets From Runner > Runner
> Assets.xcassets<br />
1. Select the AppIcon item, scroll down to the bottom to select the image size
1024 pt.</span></p><p style="background: white; box-sizing: inherit; font-size: 1.125rem; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0in; vertical-align: baseline;"><span style="color: #3d3d3d; font-family: inherit; font-size: 13.5pt;">2.Right-click : Open in Finder<br />
3. Double Click on that photo to open<br />
4. Select File > Export...<br />
5. In the Export screen: Untick Alpha, save the image file </span></p><p style="background: white; box-sizing: inherit; font-size: 1.125rem; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0in; vertical-align: baseline;"><span style="color: #3d3d3d; font-family: inherit; font-size: 13.5pt;">6. Replace the entire App icon with that<br />
Image </span></p><p style="background: white; box-sizing: inherit; font-size: 1.125rem; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0in; vertical-align: baseline;"><span style="color: #3d3d3d; font-family: inherit; font-size: 13.5pt;">7. Archive and Distribute => OK<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5746314847824244851.post-47000931676923068892022-11-01T18:45:00.003-05:002022-11-01T18:45:18.084-05:00Generate Random Numbers in .NET6<p> We can generate random number using the following code:</p><p>Console.WriteLine("Generate Randoms!");</p><p>var objRandom = new Random();</p><p>var myValue = objRandom.Next();</p><p>Console.WriteLine($"{myValue}");</p><p>In the above example, you obtain an int number as result.</p><p>You can use the methods NextBytes and NextDouble to obtain the results to obtain random bytes or random doubles values.</p><p><br /></p><p>In .NET 6 you can use the class RandomNumberGenerator present in the namespace System.Security.Cryptography.</p><p><br /></p><p> Console.WriteLine("Generate Randoms in .NET 6!");</p><p> var objRandom = RandomNumberGenerator.Create();</p><p> var objBytes = new byte[sizeof(int)]; // 4 bytes</p><p> objRandom.GetNonZeroBytes(objBytes);</p><p> var myResult = BitConverter.ToInt32(objBytes, 0);</p><p> Console.WriteLine($"{myResult}");</p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5746314847824244851.post-49735290574554010482022-10-28T10:41:00.005-05:002022-10-28T10:41:55.562-05:00Copy to Clipboard using Javascript<p> Copying the text to clipboard makes it easier to use the web page, so users will definitely like this functionality. You can achieve it using JavaScript.</p><p>Note: For this function to work in production environment, make sure your website has SSL Certificate</p><p>Sample:</p><p> <asp:Button ID="btnCopyResult" Visible ="false" OnClientClick="CopyToClipBoard();" class="btn btn-primary btn-sm" runat="server" Text="Copy Result" /> </p><p> <script type="text/javascript"></p><p> function CopyToClipBoard()</p><p> {</p><p>var sData = "Copy ME!";</p><p>try </p><p>{</p><p> navigator.clipboard.writeText(sData);</p><p> return true;</p><p> }</p><p> catch (err) </p><p>{</p><p> alert('Could not write to clipboard', err);</p><p> return false;</p><p>}</p><p>}</p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5746314847824244851.post-71458396172163955332022-10-24T21:04:00.001-05:002022-10-24T21:04:04.894-05:00Means of Persisting Form Data<p> <span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;">There are many ways of persisting form data after the form has been submitted. Some of the more popular ways include the following:</span></p><ul style="background-color: white; box-sizing: inherit; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px; list-style: none; margin: 16px 0px 16px 38px; outline-color: inherit; padding: 0px;"><li style="box-sizing: inherit; list-style: disc; margin: 0px; outline-color: inherit; outline-style: initial; outline-width: 0px; padding: 0px;"><p style="box-sizing: inherit; margin: 1rem 0px 0px; outline-color: inherit; overflow-wrap: break-word; padding: 0px;">The values of form fields can be stored in the <span style="box-sizing: inherit; font-weight: 600; outline-color: inherit;">Session</span> object. Data can be added to the <span style="box-sizing: inherit; font-weight: 600; outline-color: inherit;">Session</span> object with a line like this (in ASP.NET):</p><pre class="code" style="-webkit-font-smoothing: auto; background-color: var(--theme-code-block); border: 1px solid var(--theme-border); box-sizing: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace !important; font-size: 0.875rem; hyphens: none; line-height: 1.3571; margin-bottom: 0px; margin-top: 1rem; outline-color: inherit; overflow-wrap: normal; overflow: auto; padding: 1rem; tab-size: 4; word-break: normal; word-spacing: normal;">Session("Name") = "Mike Davis";
</pre><p style="box-sizing: inherit; margin: 1rem 0px 0px; outline-color: inherit; overflow-wrap: break-word; padding: 0px;"></p><p style="box-sizing: inherit; margin: 1rem 0px 0px; outline-color: inherit; overflow-wrap: break-word; padding: 0px;">Session information can be stored in various locations: inside the ASP.NET runtime process, inside a dedicated Microsoft Windows® service, or inside a Microsoft SQL Server™ database. However, using the <span style="box-sizing: inherit; font-weight: 600; outline-color: inherit;">Session</span> object, in any of these locations, is costly in server memory. In addition, you have to read the values out of session and put them back into the form on each page load. This routine code bulks up your pages.</p></li><li style="box-sizing: inherit; list-style: disc; margin: 0px; outline-color: inherit; outline-style: initial; outline-width: 0px; padding: 0px;"><p style="box-sizing: inherit; margin: 1rem 0px 0px; outline-color: inherit; overflow-wrap: break-word; padding: 0px;">Another option to persisting data is to duplicate your form content in a hidden field that is posted back to the server. The HiddenField control is used to store a value that needs to be persisted across posts to the server. It is rendered as an <input type= "hidden"/> element. Normally view state, session state, and cookies are used to maintain the state of a Web Forms page.</p></li></ul><br /><div><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;"> </span></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5746314847824244851.post-81527000141098891952022-10-24T10:57:00.001-05:002022-10-24T20:31:26.557-05:00Error: 1260 This Program is Blocked by Group Policy Plesk<p> 1026 This program is blocked by group policy. For more information, contact the system administrator.(GoDaddy server):</p><p>We can also eradicate the error “1026 This program block by group policy. For more information, contact the system administrator.” while hosting the asp.net mvc application published copy to the GoDaddy account. We can solve the issues by removing all of the contents inside the system.codedom tag in web.config file. </p><p>Go to web.config file in the project folder then search for system.codedom tag and removed all the contents inside the system.codedom tag. </p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5746314847824244851.post-69687572546662601252022-09-26T15:49:00.003-05:002022-09-26T15:49:39.778-05:00Adding an image and text both in asp.net button<p> <asp:Button ID="btnTestSample" Width="35" Height="25" runat="server" Text="lb" CssClass="cssTestSample" /></p><p> <style type="text/css"></p><p> .cssTestSample{</p><p> border: 1px solid #563d7c;</p><p> border-radius: 5px;</p><p> padding: 0px 25px 0px 3px;</p><p> background: url(../Images/MyTestImage.png) </p><p> left 18px top 5px no-repeat ;</p><p> }</p><p><br /></p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5746314847824244851.post-24213866117002265232022-09-14T10:58:00.003-05:002022-09-14T14:06:32.584-05:00HTML Formatting Elements<p><span face="Verdana, sans-serif" style="background-color: white; font-size: 15px;">Here goes HTML list of formatting elements:</span></p><ul style="background-color: white; box-sizing: inherit; font-family: Verdana, sans-serif; font-size: 15px;"><li style="box-sizing: inherit;"><code class="w3-codespan" style="background-color: rgba(222, 222, 222, 0.3); box-sizing: inherit; color: crimson; font-family: Consolas, Menlo, "courier new", monospace; font-size: 15.75px; padding-left: 4px; padding-right: 4px;"><b></code> - Bold text</li><li style="box-sizing: inherit;"><code class="w3-codespan" style="background-color: rgba(222, 222, 222, 0.3); box-sizing: inherit; color: crimson; font-family: Consolas, Menlo, "courier new", monospace; font-size: 15.75px; padding-left: 4px; padding-right: 4px;"><strong></code> - Important text</li><li style="box-sizing: inherit;"><code class="w3-codespan" style="background-color: rgba(222, 222, 222, 0.3); box-sizing: inherit; color: crimson; font-family: Consolas, Menlo, "courier new", monospace; font-size: 15.75px; padding-left: 4px; padding-right: 4px;"><i></code> - Italic text</li><li style="box-sizing: inherit;"><code class="w3-codespan" style="background-color: rgba(222, 222, 222, 0.3); box-sizing: inherit; color: crimson; font-family: Consolas, Menlo, "courier new", monospace; font-size: 15.75px; padding-left: 4px; padding-right: 4px;"><em></code> - Emphasized text</li><li style="box-sizing: inherit;"><code class="w3-codespan" style="background-color: rgba(222, 222, 222, 0.3); box-sizing: inherit; color: crimson; font-family: Consolas, Menlo, "courier new", monospace; font-size: 15.75px; padding-left: 4px; padding-right: 4px;"><mark></code> - Marked text</li><li style="box-sizing: inherit;"><code class="w3-codespan" style="background-color: rgba(222, 222, 222, 0.3); box-sizing: inherit; color: crimson; font-family: Consolas, Menlo, "courier new", monospace; font-size: 15.75px; padding-left: 4px; padding-right: 4px;"><small></code> - Smaller text</li><li style="box-sizing: inherit;"><code class="w3-codespan" style="background-color: rgba(222, 222, 222, 0.3); box-sizing: inherit; color: crimson; font-family: Consolas, Menlo, "courier new", monospace; font-size: 15.75px; padding-left: 4px; padding-right: 4px;"><del></code> - Deleted text</li><li style="box-sizing: inherit;"><code class="w3-codespan" style="background-color: rgba(222, 222, 222, 0.3); box-sizing: inherit; color: crimson; font-family: Consolas, Menlo, "courier new", monospace; font-size: 15.75px; padding-left: 4px; padding-right: 4px;"><ins></code> - Inserted text</li><li style="box-sizing: inherit;"><code class="w3-codespan" style="background-color: rgba(222, 222, 222, 0.3); box-sizing: inherit; color: crimson; font-family: Consolas, Menlo, "courier new", monospace; font-size: 15.75px; padding-left: 4px; padding-right: 4px;"><sub></code> - Subscript text</li><li style="box-sizing: inherit;"><code class="w3-codespan" style="background-color: rgba(222, 222, 222, 0.3); box-sizing: inherit; color: crimson; font-family: Consolas, Menlo, "courier new", monospace; font-size: 15.75px; padding-left: 4px; padding-right: 4px;"><sup></code> - Superscript text</li></ul>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5746314847824244851.post-8386481882779045332022-09-09T22:51:00.003-05:002022-09-09T22:51:36.228-05:00No iOS signing iddentities match the specified provisioning profile "Name of profile"<p> To solve this issue, try the following steps:</p><p></p><ol style="text-align: left;"><li>Check if the apple certificate (distribution/development) is still valid at developers.apple.com.</li><li>if certificate has expired then create a new certificate.</li><li>download the certificate and double click so that its added to xcode. Verify that certificate is present in xCode.</li><li>Now import this certificate to apple keychain. Go to Keychain, click Login, click Certificates on the top bar, then select the certificate, right click it and export as a p12 file, pay attention to remembering the password.</li><li>Move the p12 file to your Windows machine, go to Tools -> Options->Xamarin ->Apple Account in VS, and click View Details, click Import Certificate, import the p12 file and input the password. Then check if the profile is in %LOCALAPPDATA%\Xamarin\iOS\Provisioning\Profiles</li></ol><p></p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5746314847824244851.post-15603972509108112482022-09-07T12:55:00.000-05:002022-09-07T12:55:18.805-05:00Reset MacBook air user account password<p> Try these steps to reset your user account password:</p><p>Shut down your MacBook Air .</p><p>Press and hold the power button (Touch ID) until the screen says "Loading startup options".</p><p>Choose Options, then click Continue.</p><p>If you're prompted for an admin password, choose "Forgot all passwords?". If you're prompted to authenticate with your Apple ID, do so to continue.</p><p>You should now see a window with four options: Restore from Time Machine, Install macOS, Safari, Disk Utility. Don't choose any of these; instead, go to the menu bar at the top of the screen and click on Utilities. Then, choose Terminal.</p><p>Type "resetpassword" without the quotes and hit Enter (Return).</p><p>If FileVault is disabled, you should be able to reset your password without issue.</p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5746314847824244851.post-2215208597132136492022-07-22T14:25:00.011-05:002022-07-22T14:32:09.650-05:00Cloud Service Model <p></p><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNNIIfV0YiT4kkQVaeRi8ygxAbxi8cXZE9lJPwNeDBEvX7RCwjKTrLRR7F0dg3W60Ep46kWBDjmus67haBztJn0ggxWKv_szzoTczPx_jp7V3l6AcGPaPZhRHscg5h9_PLiu1HcNpkcqkCP7fai_YBHC6aj-Oilq-kBLlMdPc3SYwXe6HZcBlmYfLKlQ/s850/Cloud-service-comparison-and-shared-security-model.ppm" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="443" data-original-width="850" height="338" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNNIIfV0YiT4kkQVaeRi8ygxAbxi8cXZE9lJPwNeDBEvX7RCwjKTrLRR7F0dg3W60Ep46kWBDjmus67haBztJn0ggxWKv_szzoTczPx_jp7V3l6AcGPaPZhRHscg5h9_PLiu1HcNpkcqkCP7fai_YBHC6aj-Oilq-kBLlMdPc3SYwXe6HZcBlmYfLKlQ/w678-h338/Cloud-service-comparison-and-shared-security-model.ppm" width="678" /></a></div><br /><br /><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div>Iaas: Infrastcture as s service</div><div><div><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;">This cloud service model is the closest to managing physical servers; a cloud provider will keep the hardware up-to-date, but operating system maintenance and network configuration is up to you as the cloud tenant. </span></div><div><span style="color: #171717; font-family: Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif;"><br /></span><div>Paas: Platform as a service</div><div><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;">This cloud service model is a managed hosting environment. The cloud provider manages the virtual machines and networking resources, and the cloud tenant deploys their applications into the managed hosting environment. </span></div><div><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;">Example: Azure app services</span></div><div><br /><div>Saas: Software as a service</div></div></div><div><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;">In this cloud service model, the cloud provider manages all aspects of the application environment, such as virtual machines, networking resources, data storage, and applications. The cloud tenant only needs to provide their data to the application managed by the cloud provider. </span></div><div><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;">Example: Microsoft Office 365</span></div></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5746314847824244851.post-64790674077532922432022-07-08T14:32:00.001-05:002022-07-08T14:32:22.851-05:00Storage options in .NET MAUI<p> <span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;">.NET MAUI provides multiple storage options for caching data locally on a device.</span></p><p><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;">The three most commonly used options for storing data locally in a .NET MAUI app are:</span></p><ul style="background-color: white; box-sizing: inherit; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px; list-style: none; margin: 16px 0px 16px 38px; outline-color: inherit; padding: 0px;"><li style="box-sizing: inherit; list-style: disc; margin: 0px; outline-color: inherit; outline-style: initial; outline-width: 0px; padding: 0px;"><span style="box-sizing: inherit; font-weight: 600; outline-color: inherit;">Preferences</span>: Stores data in key-value pairs</li><li style="box-sizing: inherit; list-style: disc; margin: 0px; outline-color: inherit; outline-style: initial; outline-width: 0px; padding: 0px;"><span style="box-sizing: inherit; font-weight: 600; outline-color: inherit;">File system</span>: Stores loose files directly on the device through file system access</li><li style="box-sizing: inherit; list-style: disc; margin: 0px; outline-color: inherit; outline-style: initial; outline-width: 0px; padding: 0px;"><span style="box-sizing: inherit; font-weight: 600; outline-color: inherit;">Database</span>: Stores data in a relational database</li></ul><div><span style="background-color: white; box-sizing: inherit; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px; font-weight: 600; outline-color: inherit;">Preferences</span><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;"> are convenient when you're working with simple pieces of data, such as user selections.</span></div><div><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;">Example:</span></div><div><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;">c#</span></div><div><span class="hljs-built_in" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">bool</span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;"> bUserDetails = ...;
...
Preferences.Set(</span><span class="hljs-string" style="background-color: #f2f2f2; box-sizing: inherit; color: #a31515; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">"UserDetails"</span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">, </span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">bUserDetails</span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">);
...
</span><span class="hljs-keyword" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">var</span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;"> savedPreference = Preferences.Get(</span><span class="hljs-string" style="background-color: #f2f2f2; box-sizing: inherit; color: #a31515; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">"UserDetails"</span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">, </span><span class="hljs-literal" style="background-color: #f2f2f2; box-sizing: inherit; color: #07704a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">false</span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">);</span></div><div><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;"><br /></span></div><div><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;">The </span><code style="border-radius: 3px; box-sizing: inherit; color: #171717; direction: ltr; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; outline-color: inherit; overflow-wrap: break-word; padding: 0.1em 0.2em;">Preferences</code><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;"> class also contains methods for determining whether a named preference exists (</span><code style="border-radius: 3px; box-sizing: inherit; color: #171717; direction: ltr; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; outline-color: inherit; overflow-wrap: break-word; padding: 0.1em 0.2em;">ContainsKey</code><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;">), deleting a preference (</span><code style="border-radius: 3px; box-sizing: inherit; color: #171717; direction: ltr; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; outline-color: inherit; overflow-wrap: break-word; padding: 0.1em 0.2em;">Remove</code><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;">), and removing all preference data (</span><code style="border-radius: 3px; box-sizing: inherit; color: #171717; direction: ltr; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; outline-color: inherit; overflow-wrap: break-word; padding: 0.1em 0.2em;">Clear</code><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;">).</span></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5746314847824244851.post-17541803290033323222022-07-08T11:56:00.004-05:002022-07-08T11:56:26.997-05:00Consume a REST service with HttpClient in .NET MAUI<p><code style="border-radius: 3px; box-sizing: inherit; color: #171717; direction: ltr; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; outline-color: inherit; overflow-wrap: break-word; padding: 0.1em 0.2em;">HttpClient</code><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;"> is a .NET class that an app can use to send HTTP requests and receive HTTP responses from a REST web service. The resources that the web service exposes are identified by a set of URIs.</span> </p><p><br /></p><p><br /></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiknKJiO2w5UiJFrM1kpJHA8L2yrxvL0u9kWwMGYpjnzCbFlzlv7tMhiTEBX7bzs2CnZxUGcqT6nTsy-IotODf5Tfjp5WAlkit8jxyYjyA1CQzhhBTNX8Pb-_9VfQD2_JGJ7SenIWlgtEWqz24OMdlBaYy1093-UlXdiFreOUx0jZry02zBXjlSmnsEpg/s1416/RestService.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="664" data-original-width="1416" height="339" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiknKJiO2w5UiJFrM1kpJHA8L2yrxvL0u9kWwMGYpjnzCbFlzlv7tMhiTEBX7bzs2CnZxUGcqT6nTsy-IotODf5Tfjp5WAlkit8jxyYjyA1CQzhhBTNX8Pb-_9VfQD2_JGJ7SenIWlgtEWqz24OMdlBaYy1093-UlXdiFreOUx0jZry02zBXjlSmnsEpg/w657-h339/RestService.png" width="657" /></a></div><br /><p></p><p>A REST web services enables a client to perform operations against data through a set of HTTP verbs.</p><p>Four most common are GET, POST, PUT, and DELETE.</p><p></p><ul style="text-align: left;"><li>The GET verb indicate that you want to retrieve a resource.</li><li>The POST verb indicate that you want to create a new resource.</li><li>The PUT verb indicate that you want to update a resource.</li><li>The DELETE verb indicate that you want to delete a resource.</li></ul><p></p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5746314847824244851.post-49834647458983304842022-07-07T15:41:00.006-05:002022-07-07T16:07:57.208-05:00Styles in .NET MAUI<p> <span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; color: #171717; font-size: 16px;">A style is a collection of setters targeted at a specific type of control. .NET MAUI requires a target type so it can make sure that the properties in your setters exist on that type.</span></p><p><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; color: #171717; font-size: 16px;">You typically define styles as resources inside a </span><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; box-sizing: inherit; color: #171717; font-size: 16px; font-weight: 600; outline-color: inherit;">ResourceDictionary</span><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; color: #171717; font-size: 16px;"> object. A resource dictionary makes it easy to use the style across multiple controls on the same page, or even across your entire application.</span></p><p><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; color: #171717; font-size: 16px;">Example:</span></p><p><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; color: #171717; font-size: 16px;">XML</span></p><p><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Style </span></span><span class="hljs-attr" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0451a5; font-size: 14px; outline-color: inherit; white-space: pre;">x:Key</span><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; color: #0101fd; font-size: 14px; white-space: pre;">=</span><span class="hljs-string" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #a31515; font-size: 14px; outline-color: inherit; white-space: pre;">"MyButtonStyle"</span><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; color: #0101fd; font-size: 14px; white-space: pre;"> </span><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; color: #0101fd; font-size: 14px; white-space: pre;"> </span><span class="hljs-attr" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="box-sizing: inherit; color: #0451a5; font-size: 14px; outline-color: inherit; white-space: pre;">TargetType</span><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; color: #0101fd; font-size: 14px; white-space: pre;">=</span><span class="hljs-string" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="box-sizing: inherit; color: #a31515; font-size: 14px; outline-color: inherit; white-space: pre;">"Button"</span><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; color: #0101fd; font-size: 14px; white-space: pre;">></span><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; color: #171717; font-size: 14px; white-space: pre;"> </span><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Setter</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Property</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"BackgroundColor"</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Value</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"#2A84D3"</span> /></span><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; color: #171717; font-size: 14px; white-space: pre;"> </span><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Setter</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Property</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"BorderColor"</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Value</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"#1C5F9B"</span> /></span></p><p><span class="xml" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #171717; font-size: 14px; outline-color: inherit; white-space: pre;"> <span class="hljs-tag" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Setter</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Property</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"BorderWidth"</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Value</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"2"</span> /></span>
<span class="hljs-tag" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Setter</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Property</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"TextColor"</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Value</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"Green"</span> /></span>
</span><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Style</span>></span></p><p><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"><br /></span></p><p><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; font-size: 14px; outline-color: inherit; white-space: pre;">Applying a Style</span></p><p><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; font-size: 14px; outline-color: inherit; white-space: pre;"><span class="hljs-tag" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Button</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Text</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"OK"</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Style</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"{StaticResource MyButtonStyle}"</span> /></span><span style="color: #171717;">
</span><span class="hljs-tag" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Button</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Text</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"Cancel"</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Style</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"{StaticResource MyButtonStyle}"</span> /></span></span></p><p><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; font-size: 14px; outline-color: inherit; white-space: pre;"><span class="hljs-tag" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;"><br /></span></span></p><p><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; outline-color: inherit;"><span class="hljs-tag" style="box-sizing: inherit; font-size: 14px; outline-color: inherit; white-space: pre;"><span face="SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, monospace">Use an implicit style for multiple controls</span></span></span></p><p style="background-color: white; box-sizing: inherit; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px; margin: 1rem 0px 0px; outline-color: inherit; overflow-wrap: break-word; padding: 0px;">Suppose your UI has 20 buttons and you want to apply the same style to all of them. With what we know so far, you'd need to assign to the <span style="box-sizing: inherit; font-weight: 600; outline-color: inherit;">Style</span> property on each button manually. I</p><p><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; outline-color: inherit;"><span class="hljs-tag" style="box-sizing: inherit; font-size: 14px; outline-color: inherit; white-space: pre;"></span></span></p><p style="background-color: white; box-sizing: inherit; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px; margin: 1rem 0px 0px; outline-color: inherit; overflow-wrap: break-word; padding: 0px;">An <em style="box-sizing: inherit; outline-color: inherit;">implicit style</em> is a style that you add to a resource dictionary without giving it an <span style="box-sizing: inherit; font-weight: 600; outline-color: inherit;">x:Key</span> identifier. Implicit styles are automatically applied to all controls of the specified <span style="box-sizing: inherit; font-weight: 600; outline-color: inherit;">TargetType</span> object.</p><p style="background-color: white; box-sizing: inherit; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px; margin: 1rem 0px 0px; outline-color: inherit; overflow-wrap: break-word; padding: 0px;"><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; font-size: 14px; outline-color: inherit; white-space: pre;">XML</span></p><p style="background-color: white; box-sizing: inherit; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px; margin: 1rem 0px 0px; outline-color: inherit; overflow-wrap: break-word; padding: 0px;"><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">ContentPage.Resources</span>></span><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; font-size: 14px; white-space: pre;">
</span><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Style</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">TargetType</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"Button"</span>></span><span class="xml" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; font-size: 14px; outline-color: inherit; white-space: pre;">
<span class="hljs-tag" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Setter</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Property</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"BackgroundColor"</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Value</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"Blue"</span> /></span>
<span class="hljs-tag" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Setter</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Property</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"BorderColor"</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Value</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"Navy"</span> /></span>
...
</span><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Style</span>></span><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; font-size: 14px; white-space: pre;">
</span><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">ContentPage.Resources</span>></span></p><p style="background-color: white; box-sizing: inherit; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px; margin: 1rem 0px 0px; outline-color: inherit; overflow-wrap: break-word; padding: 0px;"><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"><br /></span></p><p style="background-color: white; box-sizing: inherit; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px; margin: 1rem 0px 0px; outline-color: inherit; overflow-wrap: break-word; padding: 0px;"><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; font-size: 14px; outline-color: inherit; white-space: pre;">Application level resource and style</span></p><p style="background-color: white; box-sizing: inherit; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px; margin: 1rem 0px 0px; outline-color: inherit; overflow-wrap: break-word; padding: 0px;"><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; font-size: 14px; outline-color: inherit; white-space: pre;">XML</span></p><p style="background-color: white; box-sizing: inherit; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px; margin: 1rem 0px 0px; outline-color: inherit; overflow-wrap: break-word; padding: 0px;"><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"><span class="hljs-tag" style="box-sizing: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Application.Resources</span>></span><span style="color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace;">
</span><span class="hljs-tag" style="box-sizing: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Color</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">x:Key</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"MyTextColor"</span>></span><span style="color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace;">Blue</span><span class="hljs-tag" style="box-sizing: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; outline-color: inherit;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Color</span>></span><span style="color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace;">
</span><span class="hljs-tag" style="box-sizing: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; outline-color: inherit;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Application.Resources</span>></span></span></p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5746314847824244851.post-20917962807197772352022-07-06T20:02:00.003-05:002022-07-07T15:42:31.419-05:00Resources in .Net MAUI<p> <span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; color: #171717; font-size: 16px;">A resource is like a symbolic constant from a programming language. You define it in one place and reference it everywhere you need it. Your code will be easier to read because you use a descriptive name instead of a "magic" value. If you need to change the value, you only need to update the definition.</span></p><p><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; color: #171717; font-size: 16px;">Every .NET MAUI XAML page has a property named </span><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; box-sizing: inherit; color: #171717; font-size: 16px; font-weight: 600; outline-color: inherit;">Resources</span><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; color: #171717; font-size: 16px;"> that can hold a </span><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; box-sizing: inherit; color: #171717; font-size: 16px; font-weight: 600; outline-color: inherit;">ResourceDictionary</span><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; color: #171717; font-size: 16px;"> object. The property is null by default, so you'll need to create a dictionary instance before you can use it. </span></p><p><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; color: #171717; font-size: 16px;">XML</span></p><p><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">ContentPage.Resources</span>></span><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; color: #171717; font-size: 14px; white-space: pre;">
</span><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">ResourceDictionary</span>></span><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; color: #171717; font-size: 14px; white-space: pre;">
</span><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; color: #171717; font-size: 14px; white-space: pre;"> </span><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Color</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">x:Key</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"PageControlTextColor"</span>></span><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; color: #171717; font-size: 14px; white-space: pre;">Blue</span><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Color</span>></span><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; color: #171717; font-size: 14px; white-space: pre;">
</span><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">ResourceDictionary</span>></span><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; color: #171717; font-size: 14px; white-space: pre;">
</span><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">ContentPage.Resources</span>></span></p><p><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"><span style="color: #171717;">...</span></span></p><p><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"><span style="color: #171717;">...</span></span></p><p><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Label</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">TextColor</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"{StaticResource PageControlTextColor}"</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">...</span> /></span></p><p><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"><br /></span></p><p><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; font-size: 14px; outline-color: inherit; white-space: pre;"><span face="SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, monospace">Set platform-specific values for a resourc</span><span face="SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, monospace" style="color: #0101fd;">e</span></span></p><p><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; font-size: 14px; outline-color: inherit; white-space: pre;"><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">ContentPage.Resources</span>></span><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="color: #171717;">
</span><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">OnPlatform</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">x:Key</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"textColor"</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">x:TypeArguments</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"Color"</span>></span><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="color: #171717;">
</span><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">On</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Platform</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"iOS"</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Value</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"Silver"</span> /></span><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="color: #171717;">
</span><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">On</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Platform</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"Android"</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Value</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"Green"</span> /></span><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="color: #171717;">
</span><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">On</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Platform</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"WinUI"</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Value</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"Yellow"</span> /></span><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="color: #171717;">
</span><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">On</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Platform</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"MacCatalyst"</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Value</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"Pink"</span> /></span><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="color: #171717;">
</span><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">OnPlatform</span>></span><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="color: #171717;">
</span><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">ContentPage.Resources</span>></span><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="color: #171717;">
...
</span><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Label</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">TextColor</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"{StaticResource textColor}"</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">...</span> /></span></span></p><p><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; font-size: 14px; outline-color: inherit; white-space: pre;"><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;"><br /></span></span></p><p><span style="background-color: #f2f2f2; font-size: 14px; white-space: pre;"><u>Dynamic Resources</u></span></p><p><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; box-sizing: inherit; color: #171717; font-size: 16px; font-weight: 600; outline-color: inherit;">DynamicResource</span><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; color: #171717; font-size: 16px;"> is another mark-up extension for looking up resources in a resource dictionary. It's similar to </span><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; box-sizing: inherit; color: #171717; font-size: 16px; font-weight: 600; outline-color: inherit;">StaticResource</span><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; color: #171717; font-size: 16px;"> in that it does a dictionary lookup when the target object is created. But it also listens for changes to the resource in the dictionary. If the resource value in the dictionary changes, </span><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; box-sizing: inherit; color: #171717; font-size: 16px; font-weight: 600; outline-color: inherit;">DynamicResource</span><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; color: #171717; font-size: 16px;"> automatically updates the UI.</span></p><p><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; color: #171717; font-size: 16px;">Example:</span></p><p><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; color: #171717; font-size: 16px;">XML</span></p><p><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; color: #0101fd; font-size: 14px; white-space: pre;"><</span><span class="hljs-name" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;">ContentPage</span><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; color: #0101fd; font-size: 14px; white-space: pre;"> </span><span class="hljs-attr" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0451a5; font-size: 14px; outline-color: inherit; white-space: pre;">...</span><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; color: #0101fd; font-size: 14px; white-space: pre;">></span></p><p><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"><span style="color: #171717;"> </span><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">ContentPage.Resources</span>></span><span style="color: #171717;">
</span><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Color</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">x:Key</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"PanelBackgroundColor"</span>></span><span style="color: #171717;">Blue</span><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Color</span>></span><span style="color: #171717;">
</span><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">ContentPage.Resources</span>></span><span style="color: #171717;">
</span><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">StackLayout</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">BackgroundColor</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"{DynamicResource PanelBackgroundColor}"</span>></span><span style="color: #171717;">
...
</span><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">StackLayout</span>></span><span style="color: #171717;">
</span><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">ContentPage</span>></span></span></p><p><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;">c#</span></p><p><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"><span class="hljs-keyword" style="box-sizing: inherit; outline-color: inherit;">this</span><span style="color: #171717;">.Resources[</span><span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"PanelBackgroundColor"</span><span style="color: #171717;">] = Colors.Green;</span></span></p><p><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"><span style="color: #171717;"><br /></span></span></p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5746314847824244851.post-6474899465356905662022-07-06T16:11:00.001-05:002022-07-06T16:11:04.280-05:00Grid in .Net MAUI<p> <code style="border-radius: 3px; box-sizing: inherit; color: #171717; direction: ltr; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; outline-color: inherit; overflow-wrap: break-word; padding: 0.1em 0.2em;">Grid</code><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;"> is a layout panel that consists of rows and columns. </span></p><p><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;">Example 1:</span></p><p><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Grid</span>></span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">
</span><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Grid.RowDefinitions</span>></span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">
</span><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">RowDefinition</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Height</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"200"</span> /></span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">
</span><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">RowDefinition</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Height</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"Auto"</span> /></span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">
</span><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">RowDefinition</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Height</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"1*"</span> /></span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">
</span><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">RowDefinition</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Height</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"2*"</span> /></span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">
</span><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Grid.RowDefinitions</span>></span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">
...
</span><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Grid</span>></span></p><p><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px; white-space: normal;">This can be shortened to:</span></span></p><p><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Grid</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">RowDefinitions</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"200, Auto, 1*, 2*"</span>></span><span style="color: #171717;">
...
</span><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Grid</span>></span></span></p><p><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px; white-space: normal;">Example 2:</span></span></span></p><p><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Grid</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">RowDefinitions</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"*, *, *"</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">ColumnDefinitions</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"*, *"</span>></span><span style="color: #171717;">
</span><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">BoxView</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Grid.Row</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"1"</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Grid.Column</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"0"</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Grid.ColumnSpan</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"2"</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">BackgroundColor</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"Navy"</span> /></span><span style="color: #171717;">
</span><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">Grid</span>></span></span></span></p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5746314847824244851.post-58739653277559490082022-07-06T11:01:00.002-05:002022-07-07T15:42:54.391-05:00StackLayout in .Net MAUI<p> <span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; color: #171717; font-size: 16px;">Stacking views in a vertical or horizontal list is a common design for user interfaces. </span><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; color: #171717; font-size: 16px;">Stacking views in a vertical or horizontal list is a common design for user interfaces.</span></p><p><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; color: #171717; font-size: 16px;">In .NET MAUI, you can add views to a </span><code style="border-radius: 3px; box-sizing: inherit; color: #171717; direction: ltr; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; outline-color: inherit; overflow-wrap: break-word; padding: 0.1em 0.2em;">StackLayout</code><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; color: #171717; font-size: 16px;"> in C# code or in XAML. </span></p><p><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; color: #171717; font-size: 16px;">Example:</span></p><p><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; color: #171717; font-size: 16px;"><u>XML</u></span></p><p><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">StackLayout</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">x:Name</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"myStack"</span>></span><span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; color: #171717; font-size: 14px; white-space: pre;">
</span><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">StackLayout</span>></span></p><p><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"><u>c#</u></span></p><p><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"><span class="hljs-keyword" style="box-sizing: inherit; outline-color: inherit;">public</span><span style="color: #171717;"> </span><span class="hljs-keyword" style="box-sizing: inherit; outline-color: inherit;">partial</span><span style="color: #171717;"> </span><span class="hljs-keyword" style="box-sizing: inherit; outline-color: inherit;">class</span><span style="color: #171717;"> </span><span class="hljs-title" style="box-sizing: inherit; color: #006881; outline-color: inherit;">MainPage</span><span style="color: #171717;"> : </span><span class="hljs-title" style="box-sizing: inherit; color: #006881; outline-color: inherit;">ContentPage</span><span style="color: #171717;">
{
</span><span class="hljs-function" style="box-sizing: inherit; color: #171717; outline-color: inherit;"><span class="hljs-keyword" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;">public</span> <span class="hljs-title" style="box-sizing: inherit; color: #006881; outline-color: inherit;">MainPage</span>(<span class="hljs-params" style="box-sizing: inherit; outline-color: inherit;"></span>)</span><span style="color: #171717;">
{
InitializeComponent();
</span><span class="hljs-keyword" style="box-sizing: inherit; outline-color: inherit;">var</span><span style="color: #171717;"> a = </span><span class="hljs-keyword" style="box-sizing: inherit; outline-color: inherit;">new</span><span style="color: #171717;"> BoxView { BackgroundColor = Colors.Silver, HeightRequest = 3</span><span class="hljs-number" style="box-sizing: inherit; color: #171717; outline-color: inherit;">0</span><span style="color: #171717;"> };
</span><span class="hljs-keyword" style="box-sizing: inherit; outline-color: inherit;">var</span><span style="color: #171717;"> b = </span><span class="hljs-keyword" style="box-sizing: inherit; outline-color: inherit;">new</span><span style="color: #171717;"> BoxView { BackgroundColor = Colors.Blue, HeightRequest = 3</span><span class="hljs-number" style="box-sizing: inherit; color: #171717; outline-color: inherit;">0</span><span style="color: #171717;"> };
</span><span class="hljs-keyword" style="box-sizing: inherit; outline-color: inherit;">var</span><span style="color: #171717;"> c = </span><span class="hljs-keyword" style="box-sizing: inherit; outline-color: inherit;">new</span><span style="color: #171717;"> BoxView { BackgroundColor = Colors.Gray, HeightRequest = 3</span><span class="hljs-number" style="box-sizing: inherit; color: #171717; outline-color: inherit;">0</span><span style="color: #171717;"> };
myStack.Children.Add(a);
myStack.Children.Add(b);
myStack.Children.Add(c);
}
}</span></span></p><p><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; color: #171717; font-size: 16px; white-space: normal;">To do the same thing in XAML, nest the children inside the </span><code style="background-color: var(--theme-inline-code); border-radius: 3px; box-sizing: inherit; color: #171717; direction: ltr; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; outline-color: inherit; overflow-wrap: break-word; padding: 0.1em 0.2em; white-space: normal;">StackLayout</code><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; color: #171717; font-size: 16px; white-space: normal;"> tags. </span></span></p><p><span class="hljs-tag" face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-size: 14px; outline-color: inherit; white-space: pre;"><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">StackLayout</span>></span><span style="color: #171717;">
</span><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">BoxView</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Color</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"Silver"</span> /></span><span style="color: #171717;">
</span><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">BoxView</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Color</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"Blue"</span> /></span><span style="color: #171717;">
</span><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">BoxView</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Color</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"Gray"</span> /></span><span style="color: #171717;">
</span><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">StackLayout</span>></span></span></p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5746314847824244851.post-50932770313516216112022-06-30T16:48:00.004-05:002022-06-30T16:55:49.730-05:00Using the Device class and OnPlatform mark-up extension in .Net MAUI<p>The DeviceInfo class is a utility class that provides device-specific information for the device on which your app is running. It exposes this information through a set of properties. The most important property is DeviceInfo.Platform. The property returns a string indicating the type of device currently in use; "Android", "iOS", "WinUI", or "macOS".</p><p>Example:</p><p><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">MyStackLayout.Padding =
DeviceInfo.Platform == DevicePlatform.iOS
? </span><span class="hljs-keyword" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">new</span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;"> Thickness(</span><span class="hljs-number" style="background-color: #f2f2f2; box-sizing: inherit; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">30</span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">, </span><span class="hljs-number" style="background-color: #f2f2f2; box-sizing: inherit; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">60</span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">, </span><span class="hljs-number" style="background-color: #f2f2f2; box-sizing: inherit; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">30</span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">, </span><span class="hljs-number" style="background-color: #f2f2f2; box-sizing: inherit; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">30</span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">) </span><span class="hljs-comment" style="background-color: #f2f2f2; box-sizing: inherit; color: green; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">// Shift down by 60 points on iOS only</span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">
: </span><span class="hljs-keyword" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">new</span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;"> Thickness(</span><span class="hljs-number" style="background-color: #f2f2f2; box-sizing: inherit; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">30</span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">); </span><span class="hljs-comment" style="background-color: #f2f2f2; box-sizing: inherit; color: green; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">// Set the default margin to be 30 points</span></p><p><br /></p><p>.NET MAUI XAML provides the OnPlatform mark-up extension that enables you to detect the runtime platform from within in your XAML code. You apply this mark-up extension as part of the XAML code that sets a property value. The extension requires you to provide the type of the property, together with a series of On Platform blocks in which you set the value of the property according to the platform.</p><p>Example:</p><p>Sample 1:</p><p><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">VerticalStackLayout</span>></span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">
</span><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">VerticalStackLayout.Padding</span>></span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">
</span><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">OnPlatform</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">x:TypeArguments</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"Thickness"</span>></span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">
</span><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">On</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Platform</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"iOS"</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Value</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"30,60,30,30"</span> /></span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">
</span><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">On</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Platform</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"Android"</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Value</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"30"</span> /></span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">
</span><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">On</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Platform</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"WinUI"</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Value</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"30"</span> /></span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">
</span><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">OnPlatform</span>></span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">
</span><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">VerticalStackLayout.Padding</span>></span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">
...
</span><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">VerticalStackLayout</span>></span></p><p>Sample 2:</p><p><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">VerticalStackLayout</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Padding</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"{OnPlatform iOS='30,60,30,30', Default='30'}"</span>></span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">
</span><span class="hljs-comment" style="background-color: #f2f2f2; box-sizing: inherit; color: green; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"><!--XAML for other controls goes here --></span><span style="background-color: #f2f2f2; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">
</span><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">VerticalStackLayout</span>></span></p><p><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">Sample 3:</span></p><p><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">VerticalStackLayout</span>></span><span style="color: #171717;">
...
</span><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">VerticalStackLayout.BackgroundColor</span>></span><span style="color: #171717;">
</span><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">OnPlatform</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">x:TypeArguments</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"Color"</span>></span><span style="color: #171717;">
</span><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">On</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Platform</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"iOS"</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Value</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"Silver"</span> /></span><span style="color: #171717;">
</span><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">On</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Platform</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"Android"</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Value</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"Green"</span> /></span><span style="color: #171717;">
</span><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">On</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Platform</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"WinUI"</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">Value</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"Yellow"</span> /></span><span style="color: #171717;">
</span><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">OnPlatform</span>></span><span style="color: #171717;">
</span><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">VerticalStackLayout.BackgroundColor</span>></span><span style="color: #171717;">
...
</span><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">VerticalStackLayout</span>></span></span></p><p><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;">Sample 4:</span></span></p><p><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"><<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">VerticalStackLayout</span> <span class="hljs-attr" style="box-sizing: inherit; color: #0451a5; outline-color: inherit;">BackgroundColor</span>=<span class="hljs-string" style="box-sizing: inherit; color: #a31515; outline-color: inherit;">"{OnPlatform WinUI=Yellow, iOS=Silver, Android=Green}"</span>></span><span style="color: #171717;">
...
</span><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"></<span class="hljs-name" style="box-sizing: inherit; outline-color: inherit;">VerticalStackLayout</span>></span></span></span></p><p><span class="hljs-tag" style="background-color: #f2f2f2; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"><span class="hljs-tag" style="box-sizing: inherit; outline-color: inherit;"><br /></span></span></p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5746314847824244851.post-61964355199669265962022-06-29T21:37:00.004-05:002022-06-29T21:38:09.633-05:00Maui sample code and its equivalent from the code behind. <p>Maui sample code and its equivalent from the code behind. </p><p><ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"</p><p> xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"</p><p> x:Class="Phoneword.MainPage"></p><p> <ScrollView></p><p> <VerticalStackLayout></p><p> <Label Text="Current count: 0"</p><p> FontSize="18"</p><p> FontAttributes="Bold"</p><p> x:Name="CounterLabel"</p><p> HorizontalOptions="Center" /></p><p> <Button Text="Click me"</p><p> Grid.Row="1"</p><p> Clicked="OnCounterClicked"</p><p> HorizontalOptions="Center" /></p><p> </VerticalStackLayout></p><p> </ScrollView></p><p></ContentPage></p><p><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="background-color: white; color: #171717; font-size: 16px;">The equivalent code in C# looks like this:</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;">public partial class TestPage : ContentPage</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;">{</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> int count = 0;</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> </span><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="color: #171717;">// Named Label - declared as a member of the class</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> Label counterLabel;</span></p><p><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="color: #171717;"> public TestPage()</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> { </span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> var myScrollView = new ScrollView();</span></p><p><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="color: #171717;"> var myStackLayout = new VerticalStackLayout();</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> myScrollView.Content = myStackLayout;</span></p><p><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="color: #171717;"> counterLabel = new Label</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> {</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> Text = "Current count: 0",</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> FontSize = 18,</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> FontAttributes = FontAttributes.Bold,</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> HorizontalOptions = LayoutOptions.Center</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> };</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> myStackLayout.Children.Add(counterLabel);</span><span face=""Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif" style="color: #171717;"> </span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> var myButton = new Button</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> {</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> Text = "Click me",</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> HorizontalOptions = LayoutOptions.Center</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> };</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> myStackLayout.Children.Add(myButton);</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"><br /></span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> myButton.Clicked += OnCounterClicked;</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"><br /></span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> this.Content = myScrollView;</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> }</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"><br /></span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> private void OnCounterClicked(object sender, EventArgs e)</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> {</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> count++;</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> counterLabel.Text = $"Current count: {count}";</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"><br /></span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> SemanticScreenReader.Announce(counterLabel.Text);</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"> }</span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;"><span style="background-color: white;"></span></span></p><p><span face="Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif" style="color: #171717;">}</span></p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5746314847824244851.post-10225156362067811622022-06-29T15:11:00.014-05:002023-10-04T12:53:48.520-05:00Some useful links related to .Net MAUI<p><a href="https://dotnet.microsoft.com/en-us/learn/maui" target="_blank">Learn .NET MAUI | Free tutorials, courses, videos, and more (microsoft.com)</a></p><p><a href="https://github.com/jsuarezruiz/awesome-dotnet-maui?WT.mc_id=dotnet-35129-website" target="_blank">GitHub - jsuarezruiz/awesome-dotnet-maui: A curated list of awesome .NET MAUI libraries and resources.</a></p><p><br /></p><p><br /></p><p><a href="https://docs.microsoft.com/en-us/dotnet/maui/what-is-maui" target="_blank">What is .NET MAUI? - .NET MAUI | Microsoft Docs</a></p><p><a href="https://docs.microsoft.com/en-us/learn/paths/build-apps-with-dotnet-maui/" target="_blank">Build mobile and desktop apps with .NET MAUI - Learn | Microsoft Docs</a> </p><p><a href="http://docs.microsoft.com/en-us/learn/dotnet-maui/build-mobile-and-desktop-apps/" target="_blank">Create a cross-platform app with .NET MAUI - Learn | Microsoft Docs</a></p><p><br /></p><h1 dir="auto" style="background-color: white; border-bottom: 1px solid var(--color-border-muted); box-sizing: border-box; color: #24292f; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; line-height: 1.25; margin-bottom: 16px; margin-left: 0px; margin-right: 0px; margin-top: 0px !important; margin: 0px 0px 16px; padding-bottom: 0.3em;">NET MAUI Samples</h1><p dir="auto" style="background-color: white; box-sizing: border-box; color: #24292f; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; font-size: 16px; margin-bottom: 16px; margin-top: 0px;">Samples built with .NET Multi-platform App UI (.NET MAUI).</p><p dir="auto" style="background-color: white; box-sizing: border-box; color: #24292f; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; font-size: 16px; margin-bottom: 16px; margin-top: 0px;"><a href="https://dot.net/maui" rel="nofollow" style="background-color: transparent; box-sizing: border-box; text-decoration-line: none;">.NET MAUI</a> is a cross-platform framework for creating mobile and desktop apps with C# and XAML. Using .NET MAUI, you can develop apps that can run on Android, iOS, iPadOS, macOS, and Windows from a single shared codebase.</p><h2 dir="auto" style="background-color: white; border-bottom: 1px solid var(--color-border-muted); box-sizing: border-box; color: #24292f; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; line-height: 1.25; margin-bottom: 16px; margin-top: 24px; padding-bottom: 0.3em;"><a aria-hidden="true" class="anchor" href="https://github.com/dotnet/maui-samples?WT.mc_id=dotnet-35129-website#official-samples" id="user-content-official-samples" style="background-color: transparent; box-sizing: border-box; float: left; line-height: 1; margin-left: -20px; padding-right: 4px; text-decoration-line: none;"><svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z" fill-rule="evenodd"></path></svg></a>Official Samples</h2><p dir="auto" style="background-color: white; box-sizing: border-box; color: #24292f; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; font-size: 16px; margin-bottom: 16px; margin-top: 0px;">Official samples can be accessed via the <a href="https://docs.microsoft.com/samples/browse/?expanded=dotnet&products=dotnet-maui" rel="nofollow" style="background-color: transparent; box-sizing: border-box; text-decoration-line: none;" target="_blank">Samples browser</a>.</p><p dir="auto" style="background-color: white; box-sizing: border-box; color: #24292f; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; font-size: 16px; margin-bottom: 16px; margin-top: 0px;">Sample highlights include:</p><ul dir="auto" style="background-color: white; box-sizing: border-box; color: #24292f; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; font-size: 16px; margin-bottom: 16px; margin-top: 0px; padding-left: 2em;"><li style="box-sizing: border-box;"><a href="https://github.com/dotnet/maui-samples/blob/main/6.0/Apps/WeatherTwentyOne" style="background-color: transparent; box-sizing: border-box; text-decoration-line: none;" target="_blank">Weather '21 App</a></li><li style="box-sizing: border-box; margin-top: 0.25em;"><a href="https://github.com/dotnet/maui-samples/blob/main/6.0/Apps/Calculator" style="background-color: transparent; box-sizing: border-box; text-decoration-line: none;" target="_blank">Calculator App</a></li><li style="box-sizing: border-box; margin-top: 0.25em;"><a href="https://github.com/microsoft/dotnet-podcasts" style="background-color: transparent; box-sizing: border-box; text-decoration-line: none;" target="_blank">.NET Podcasts App</a></li><li style="box-sizing: border-box; margin-top: 0.25em;"><a href="https://github.com/dotnet/maui-samples/blob/main/6.0/Navigation" style="background-color: transparent; box-sizing: border-box; text-decoration-line: none;" target="_blank">Navigation Samples</a></li><li style="box-sizing: border-box; margin-top: 0.25em;"><a href="https://github.com/dotnet/maui-samples/blob/main/6.0/Beginners-Series" style="background-color: transparent; box-sizing: border-box; text-decoration-line: none;" target="_blank">Beginner's Series Task App Sample</a></li></ul><h2 dir="auto" style="background-color: white; border-bottom: 1px solid var(--color-border-muted); box-sizing: border-box; color: #24292f; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; line-height: 1.25; margin-bottom: 16px; margin-top: 24px; padding-bottom: 0.3em;"><a aria-hidden="true" class="anchor" href="https://github.com/dotnet/maui-samples?WT.mc_id=dotnet-35129-website#community-samples" id="user-content-community-samples" style="background-color: transparent; box-sizing: border-box; float: left; line-height: 1; margin-left: -20px; padding-right: 4px; text-decoration-line: none;"><svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z" fill-rule="evenodd"></path></svg></a>Community Samples</h2><ul dir="auto" style="background-color: white; box-sizing: border-box; color: #24292f; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; font-size: 16px; margin-bottom: 16px; margin-top: 0px; padding-left: 2em;"><li style="box-sizing: border-box;"><a href="https://github.com/rachelkang/recipeSearch" style="background-color: transparent; box-sizing: border-box; text-decoration-line: none;" target="_blank">Rachel's Recipes App</a></li><li style="box-sizing: border-box; margin-top: 0.25em;"><a href="https://github.com/jsuarezruiz/awesome-dotnet-maui" style="background-color: transparent; box-sizing: border-box; text-decoration-line: none;" target="_blank">Awesome .NET MAUI</a></li></ul><h2 dir="auto" style="background-color: white; border-bottom: 1px solid var(--color-border-muted); box-sizing: border-box; color: #24292f; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; line-height: 1.25; margin-bottom: 16px; margin-top: 24px; padding-bottom: 0.3em;"><a aria-hidden="true" class="anchor" href="https://github.com/dotnet/maui-samples?WT.mc_id=dotnet-35129-website#net-maui-links" id="user-content-net-maui-links" style="background-color: transparent; box-sizing: border-box; float: left; line-height: 1; margin-left: -20px; padding-right: 4px; text-decoration-line: none;"><svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z" fill-rule="evenodd"></path></svg></a>.NET MAUI Links</h2><ul dir="auto" style="background-color: white; box-sizing: border-box; color: #24292f; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; font-size: 16px; margin-bottom: 16px; margin-top: 0px; padding-left: 2em;"><li style="box-sizing: border-box;"><a href="https://dot.net/maui" rel="nofollow" style="background-color: transparent; box-sizing: border-box; text-decoration-line: none;" target="_blank">.NET MAUI Website</a></li><li style="box-sizing: border-box; margin-top: 0.25em;"><a href="https://docs.microsoft.com/dotnet/maui" rel="nofollow" style="background-color: transparent; box-sizing: border-box; text-decoration-line: none;" target="_blank">.NET MAUI Documentation</a></li><li style="box-sizing: border-box; margin-top: 0.25em;"><a href="https://devblogs.microsoft.com/dotnet/category/maui/" rel="nofollow" style="background-color: transparent; box-sizing: border-box; text-decoration-line: none;" target="_blank">.NET MAUI Blog</a></li><li style="box-sizing: border-box; margin-top: 0.25em;"><a href="https://github.com/dotnet/maui" style="background-color: transparent; box-sizing: border-box; text-decoration-line: none;" target="_blank">.NET MAUI GitHub</a></li></ul><h2 dir="auto" style="background-color: white; border-bottom: 1px solid var(--color-border-muted); box-sizing: border-box; color: #24292f; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; line-height: 1.25; margin-bottom: 16px; margin-top: 24px; padding-bottom: 0.3em;"><a aria-hidden="true" class="anchor" href="https://github.com/dotnet/maui-samples?WT.mc_id=dotnet-35129-website#net-foundation" id="user-content-net-foundation" style="background-color: transparent; box-sizing: border-box; float: left; line-height: 1; margin-left: -20px; padding-right: 4px; text-decoration-line: none;"><svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z" fill-rule="evenodd"></path></svg></a>.NET Foundation</h2><p dir="auto" style="background-color: white; box-sizing: border-box; color: #24292f; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; font-size: 16px; margin-bottom: 16px; margin-top: 0px;">There are many .NET related projects on GitHub.</p><ul dir="auto" style="background-color: white; box-sizing: border-box; color: #24292f; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; font-size: 16px; margin-bottom: 16px; margin-top: 0px; padding-left: 2em;"><li style="box-sizing: border-box;"><a href="https://github.com/Microsoft/dotnet" style="background-color: transparent; box-sizing: border-box; text-decoration-line: none;" target="_blank">.NET home repo</a> - links to hundreds of .NET projects, from Microsoft and the community.</li><li style="box-sizing: border-box; margin-top: 0.25em;"><a href="https://docs.microsoft.com/aspnet/core/" rel="nofollow" style="background-color: transparent; box-sizing: border-box; text-decoration-line: none;" target="_blank">ASP.NET Core home</a> - the best place to start learning about ASP.NET Core.</li></ul>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5746314847824244851.post-27732769194122396252022-04-26T14:02:00.003-05:002022-04-26T14:02:16.000-05:00https://mvtd.events.microsoft.com/<p> <a href="https://mvtd.events.microsoft.com/">Microsoft Virtual Training Days</a></p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5746314847824244851.post-41632714847843294562021-06-22T21:35:00.000-05:002021-06-22T21:35:01.593-05:00Manual provisioning for Xamarin.iOS - Xamarin | Microsoft Docs<p>Once Xamarin.iOS has been successfully installed, the next step in iOS development is to provision your iOS device. This guide explores using manual provisioning to set up development certificates and profiles. </p><p><a href="https://docs.microsoft.com/en-us/xamarin/ios/get-started/installation/device-provisioning/manual-provisioning?tabs=windows#download">Manual provisioning for Xamarin.iOS - Xamarin | Microsoft Docs</a></p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5746314847824244851.post-62575517853112907672021-04-13T12:19:00.005-05:002021-04-13T12:34:37.874-05:00How To Fix TF30063 Error - You Are Not Authorized To Access Team Foundation Service Error<p>If you get this error in Visual Studio TFS which says "You are not authorised to access Team Foundation Service" with error code TF30063. This error mostly happens when you are going to check in pending changes to TFS.</p><p>I was able to fix this error using following steps:</p><p>1) Try to connect to project again, just click to icon next to Home icon and choose your project and then right click on project and click to Connect. This will be reconnected with project and we will able to access your project.</p><p><br /></p><p>2). As we know, TFS is directly connect with IE browser. So, just open your Internet Explorer and logout with TFS account if you logged in. After successfully logging out, you just need to login again with your TFS account in IE. Before logginin into IE, please check the version of IE browser. It should be above IE 9. Once you have successfully logged in with TFS in IE, go to Visual Studio and check and the error will be gone.</p><p>3) you can clear TFS cache:</p><p>C:\Users\UserName\AppData\Local\Microsoft\Team Foundation\7.0\Cache</p><p>4) If all above steps have failed to resolve this issue, try removing TFS server and add again with Visual Studio.</p><p><br /></p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5746314847824244851.post-19106909074613172622020-12-05T10:24:00.003-06:002020-12-05T10:24:50.533-06:00Thread.Sleep vs. Task.Delay in c#<p><b>Thread.Sleep vs. Task.Delay in c# </b></p><p>The biggest difference between Task.Delay and Thread.Sleep is that Task.Delay is intended to run asynchronously. It does not make sense to use Task.Delay in synchronous code. It is a VERY bad idea to use Thread.Sleep in asynchronous code.</p><p><br /></p><p><span style="color: #3d85c6;">void ThreadSleepSample()</span></p><p><span style="color: #3d85c6;">{</span></p><p><span style="color: #3d85c6;"> Thread.Sleep(1000);</span></p><p><span style="color: #3d85c6;"> }</span></p><p><span style="color: #3d85c6;"><br /></span></p><p><span style="color: #3d85c6;"> async Task TaskDelaySample()</span></p><p><span style="color: #3d85c6;">{</span></p><p><span style="color: #3d85c6;"> await Task.Delay(1000);</span></p><p><span style="color: #3d85c6;"> }</span></p><p><b>Both Thread.Sleep() and Task.Delay() are used to suspend the execution of a program (thread) for a given timespan. </b></p><p><br /></p><p><b>Thread.Sleep()</b></p><p>This is the classic way of suspending execution. This method will suspend the current thread until the given amount of time has elapsed. When you call Thread.Sleep in the above way, there is nothing you can do to abort this except waiting until the time elapses or by restarting the application. That’s because Thread.Sleep suspends the thread that's making the call. </p><div><div><br /></div><div><b>Task.Delay()</b></div><div><br /></div><div>Task.Delay acts in a very different way than Thread.Sleep. Basically, Task.Delay will create a task which will complete after a time delay. Task.Delay is not blocking the calling thread so the UI will remain responsive.</div><div><br /></div><div>Behind the scenes there is a timer ticking until the specified time. Since the timer controls the delay, we can cancel the delay at any time simply by stopping the timer. To cancel,we can modifying the above TaskDelaySample method as follows:</div></div><div><br /></div><div><div><span style="color: #3d85c6;">CancellationTokenSource tokenSource = new CancellationTokenSource(); </span></div><div><span style="color: #3d85c6;"><br /></span></div><div><span style="color: #3d85c6;">async Task TaskDelaySample()</span></div><div><span style="color: #3d85c6;">{ </span></div><div><span style="color: #3d85c6;"> try</span></div><div><span style="color: #3d85c6;"> {</span></div><div><span style="color: #3d85c6;"> await Task.Delay(1000, tokenSource.Token);</span></div><div><span style="color: #3d85c6;"> }</span></div><div><span style="color: #3d85c6;"> catch (TaskCanceledException ex)</span></div><div><span style="color: #3d85c6;"> {</span></div><div><span style="color: #3d85c6;"> </span></div><div><span style="color: #3d85c6;"> }</span></div><div><span style="color: #3d85c6;"> catch (Exception ex)</span></div><div><span style="color: #3d85c6;"> { </span></div><div><span style="color: #3d85c6;"> </span></div><div><span style="color: #3d85c6;"> }</span></div><div><span style="color: #3d85c6;">}</span></div></div><div><br /></div><div>In the call to Task.Delay we 've added a cancellation token. When the task gets cancelled, it will throw a TaskCanceledException Jump .We are catching the exception and suppressing it, because we don't want to show any message about that.</div><div><br /></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5746314847824244851.post-30420657352907162952020-11-22T21:06:00.001-06:002020-11-22T21:06:27.435-06:00async await in c#<p> Async methods can have the following return types:</p><p><b>Task,</b> for an async method that performs an operation but returns no value.</p><p>Task<TResult>, for an async method that returns a value.</p><p>void, for an event handler.</p><p>Task return type</p><p>Async methods that don't contain a return statement or that contain a return statement that doesn't return an operand usually have a return type of Task. Such methods return void if they run synchronously. If you use a Task return type for an async method, a calling method can use an await operator to suspend the caller's completion until the called async method has finished.</p><p>Example:</p><p><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;">In the following example, the </span><code style="border-radius: 3px; box-sizing: inherit; color: #171717; direction: ltr; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; outline-color: inherit; overflow-wrap: break-word; padding: 0.1em 0.2em;">WaitAndApologizeAsync</code><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;"> method doesn't contain a </span><code style="border-radius: 3px; box-sizing: inherit; color: #171717; direction: ltr; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; outline-color: inherit; overflow-wrap: break-word; padding: 0.1em 0.2em;">return</code><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;"> statement, so the method returns a </span><a data-linktype="absolute-path" href="https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task" style="background-color: white; box-sizing: inherit; cursor: pointer; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px; outline-color: inherit; outline-style: initial; outline-width: 0px; overflow-wrap: break-word; text-decoration-line: none;">Task</a><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;"> object. Returning a </span><code style="border-radius: 3px; box-sizing: inherit; color: #171717; direction: ltr; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; outline-color: inherit; overflow-wrap: break-word; padding: 0.1em 0.2em;">Task</code><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;"> enables </span><code style="border-radius: 3px; box-sizing: inherit; color: #171717; direction: ltr; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; outline-color: inherit; overflow-wrap: break-word; padding: 0.1em 0.2em;">WaitAndApologizeAsync</code><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;"> to be awaited. The </span><a data-linktype="absolute-path" href="https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task" style="background-color: white; box-sizing: inherit; cursor: pointer; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px; outline-color: inherit; outline-style: initial; outline-width: 0px; overflow-wrap: break-word; text-decoration-line: none;">Task</a><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;"> type doesn't include a </span><code style="border-radius: 3px; box-sizing: inherit; color: #171717; direction: ltr; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; outline-color: inherit; overflow-wrap: break-word; padding: 0.1em 0.2em;">Result</code><span style="background-color: white; color: #171717; font-family: "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;"> property because it has no return value.</span></p><p><span class="hljs-function" style="background-color: #fafafa; box-sizing: inherit; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"><span class="hljs-keyword" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;">public</span> <span class="hljs-keyword" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;">static</span> <span class="hljs-keyword" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;">async</span> Task <span class="hljs-title" style="box-sizing: inherit; color: #007d9a; outline-color: inherit;">DisplayCurrentInfoAsync</span>(<span class="hljs-params" style="box-sizing: inherit; outline-color: inherit;"></span>)</span><span style="background-color: #fafafa; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">
{
</span><span class="hljs-keyword" style="background-color: #fafafa; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">await</span><span style="background-color: #fafafa; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;"> WaitAndApologizeAsync();
Console.WriteLine(</span><span class="hljs-string" style="background-color: #fafafa; box-sizing: inherit; color: #a31515; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">$"Today is <span class="hljs-subst" style="box-sizing: inherit; color: var(--theme-text); outline-color: inherit;">{DateTime.Now:D}</span>"</span><span style="background-color: #fafafa; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">);
Console.WriteLine(</span><span class="hljs-string" style="background-color: #fafafa; box-sizing: inherit; color: #a31515; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">$"The current time is <span class="hljs-subst" style="box-sizing: inherit; color: var(--theme-text); outline-color: inherit;">{DateTime.Now.TimeOfDay:t}</span>"</span><span style="background-color: #fafafa; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">);
Console.WriteLine(</span><span class="hljs-string" style="background-color: #fafafa; box-sizing: inherit; color: #a31515; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">"The current temperature is 76 degrees."</span><span style="background-color: #fafafa; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">);
}
</span><span class="hljs-function" style="background-color: #fafafa; box-sizing: inherit; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"><span class="hljs-keyword" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;">static</span> <span class="hljs-keyword" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;">async</span> Task <span class="hljs-title" style="box-sizing: inherit; color: #007d9a; outline-color: inherit;">WaitAndApologizeAsync</span>(<span class="hljs-params" style="box-sizing: inherit; outline-color: inherit;"></span>)</span><span style="background-color: #fafafa; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">
{
</span><span class="hljs-keyword" style="background-color: #fafafa; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">await</span><span style="background-color: #fafafa; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;"> Task.Delay(</span><span class="hljs-number" style="background-color: #fafafa; box-sizing: inherit; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">2000</span><span style="background-color: #fafafa; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">);
Console.WriteLine(</span><span class="hljs-string" style="background-color: #fafafa; box-sizing: inherit; color: #a31515; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">"Sorry for the delay...\n"</span><span style="background-color: #fafafa; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">);
}</span></p><p><span style="background-color: #fafafa; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;"><br /></span></p><p><span style="background-color: #fafafa; font-size: 14px; white-space: pre;"><span style="color: #171717; font-family: SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, monospace;"><b>Task<TResult> return type</b>
The Task<TResult> return type is used for an async method that contains </span></span></p><p><span style="background-color: #fafafa; font-size: 14px; white-space: pre;"><span style="color: #171717; font-family: SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, monospace;">a return statement in which the operand is TResult.
In the following example, the GetLeisureHoursAsync method contains a </span></span></p><p><span style="background-color: #fafafa; font-size: 14px; white-space: pre;"><span style="color: #171717; font-family: SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, monospace;">return statement that returns an integer. Therefore, the method </span></span></p><p><span style="background-color: #fafafa; font-size: 14px; white-space: pre;"><span style="color: #171717; font-family: SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, monospace;">declaration must specify a return type of Task<int>. The FromResult async </span></span></p><p><span style="background-color: #fafafa; font-size: 14px; white-space: pre;"><span style="color: #171717; font-family: SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, monospace;">method is a placeholder for an operation that returns a DayOfWeek.</span></span></p><p><span class="hljs-function" style="background-color: #fafafa; box-sizing: inherit; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"><span class="hljs-keyword" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;">public</span> <span class="hljs-keyword" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;">static</span> <span class="hljs-keyword" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;">async</span> Task <span class="hljs-title" style="box-sizing: inherit; color: #007d9a; outline-color: inherit;">ShowTodaysInfoAsync</span>(<span class="hljs-params" style="box-sizing: inherit; outline-color: inherit;"></span>)</span><span style="background-color: #fafafa; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">
{
</span><span class="hljs-keyword" style="background-color: #fafafa; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">string</span><span style="background-color: #fafafa; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;"> message =
</span><span class="hljs-string" style="background-color: #fafafa; box-sizing: inherit; color: #a31515; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">$"Today is <span class="hljs-subst" style="box-sizing: inherit; color: var(--theme-text); outline-color: inherit;">{DateTime.Today:D}</span>\n"</span><span style="background-color: #fafafa; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;"> +
</span><span class="hljs-string" style="background-color: #fafafa; box-sizing: inherit; color: #a31515; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">"Today's hours of leisure: "</span><span style="background-color: #fafafa; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;"> +
</span><span class="hljs-string" style="background-color: #fafafa; box-sizing: inherit; color: #a31515; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">$"<span class="hljs-subst" style="box-sizing: inherit; color: var(--theme-text); outline-color: inherit;">{<span class="hljs-keyword" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;">await</span> GetLeisureHoursAsync()}</span>"</span><span style="background-color: #fafafa; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">;
Console.WriteLine(message);
}
</span><span class="hljs-function" style="background-color: #fafafa; box-sizing: inherit; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;"><span class="hljs-keyword" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;">static</span> <span class="hljs-keyword" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;">async</span> Task<<span class="hljs-keyword" style="box-sizing: inherit; color: #0101fd; outline-color: inherit;">int</span>> <span class="hljs-title" style="box-sizing: inherit; color: #007d9a; outline-color: inherit;">GetLeisureHoursAsync</span>(<span class="hljs-params" style="box-sizing: inherit; outline-color: inherit;"></span>)</span><span style="background-color: #fafafa; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">
{
DayOfWeek today = </span><span class="hljs-keyword" style="background-color: #fafafa; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">await</span><span style="background-color: #fafafa; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;"> Task.FromResult(DateTime.Now.DayOfWeek);
</span><span class="hljs-keyword" style="background-color: #fafafa; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">int</span><span style="background-color: #fafafa; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;"> leisureHours =
today </span><span class="hljs-keyword" style="background-color: #fafafa; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">is</span><span style="background-color: #fafafa; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;"> DayOfWeek.Saturday || today </span><span class="hljs-keyword" style="background-color: #fafafa; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">is</span><span style="background-color: #fafafa; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;"> DayOfWeek.Sunday
? </span><span class="hljs-number" style="background-color: #fafafa; box-sizing: inherit; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">16</span><span style="background-color: #fafafa; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;"> : </span><span class="hljs-number" style="background-color: #fafafa; box-sizing: inherit; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">5</span><span style="background-color: #fafafa; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;">;
</span><span class="hljs-keyword" style="background-color: #fafafa; box-sizing: inherit; color: #0101fd; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; outline-color: inherit; white-space: pre;">return</span><span style="background-color: #fafafa; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;"> leisureHours;
}</span></p><p><span style="background-color: #fafafa; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;"><br /></span></p><p><span style="background-color: #fafafa; color: #171717; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; white-space: pre;"><br /></span></p>Unknownnoreply@blogger.com0