Xamarin.Forms: Android app forgets the style when using DynamicResource

If you break the look and feel of the app when you switch apps on mobile, and you use styles as DynamicResources, which you add as MergedDictionaries in App.Xaml,
you should pay attention to this:

When you don’t exit the Android app, but bring it back to the foreground after a very long time, the constructor logic in App.xaml.cs runs again. Don’t forget to add MergedDictionary from code, which contains the styles. If you forget this, all controls will appear in the app with their default look.

I wrote about how to handle restarting the application here: https://www.banditoth.hu/2021/03/22/xamarin-forms-reopening-application-best-pratices/

This content has 3 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

Xamarin.Forms : Focus to the entry and set the cursor after the last character

If you want to make the cursor in Xamarin.Forms Entry blink behind the text you have already typed, instead of in front of it, after focusing, you need to do the following:

Subscribe to the Focused event of the Entry and modify the eventhandler as follows:

		public void OnEntryFocused(object sender, EventArgs args)
		{
			EntryInstance.CursorPosition = EntryInstance?.Text?.Length ?? 0;
		}

You can find more information about the CursorPosition at: https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.entry.cursorposition?view=xamarin-forms

This content has 3 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

Xamarin.Forms: ‘MSBuild:UpdateDesignTimeXaml’ code generator crashed solution

If you are facing an issue after updating the Xamarin.Forms version in your project, with the following error:

SOMEXAMLFILE.xaml: Error: The 'MSBuild:UpdateDesignTimeXaml' code generator crashed: Not connected
  at MonoDevelop.Core.Execution.RemoteProcessConnection.PostMessage (MonoDevelop.Core.Execution.BinaryMessage message, System.Threading.Tasks.TaskCompletionSource`1[TResult] cs, System.Boolean checkInitialized) [0x000c3] in /Users/builder/azdo/_work/2/s/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Execution/RemoteProcessConnection.cs:438 
  at MonoDevelop.Core.Execution.RemoteProcessConnection.SendMessage (MonoDevelop.Core.Execution.BinaryMessage message) [0x00031] in /Users/builder/azdo/_work/2/s/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Execution/RemoteProcessConnection.cs:385 
  at MonoDevelop.Projects.MSBuild.RemoteBuildEngineManager+<>c__DisplayClass20_0.<GetBuildEngine>b__5 () [0x00252] in /Users/builder/azdo/_work/2/s/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/RemoteBuildEngineManager.cs:323 
  at MonoDevelop.Projects.MSBuild.RemoteBuildEngineManager.GetBuildEngine (MonoDevelop.Core.Assemblies.TargetRuntime runtime, System.String minToolsVersion, System.String solutionFile, System.String group, System.Object buildSessionId, System.Boolean setBusy, System.Boolean allowBusy) [0x0036f] in /Users/builder/azdo/_work/2/s/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/RemoteBuildEngineManager.cs:273 
  at MonoDevelop.Projects.MSBuild.RemoteBuildEngineManager.GetRemoteProjectBuilder (System.String projectFile, System.String solutionFile, MonoDevelop.Core.Assemblies.TargetRuntime runtime, System.String minToolsVersion, System.Object buildSessionId, System.Boolean setBusy, System.Boolean allowBusy) [0x000df] in /Users/builder/azdo/_work/2/s/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/RemoteBuildEngineManager.cs:176 [...]

Then clean your solution, and restart Visual Studio for Mac.

This content has 3 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

Xamarin.UWP deployment failure: 0x80073D1F

Registering the application to run from layout...
DEP0700: Registration of the app failed. [0x80073D1F] 
	DeploymentSucceeded = False
	DeploymentError = Err_Deploy_Register
	DeploymentUserError = False
	DeploymentHRESULT = 2147958047
	HasSharedCode = False
	Target.Id = 512
	ProjectGuid = {5894aed2-9bb1-434b-8b49-3b86572709b7}
	Project.TargetPlatformVersion = 10.0.19041.0
	Project.TargetPlatformMinVersion = 10.0.17763.0
Deleting file "vs.appxrecipe" from layout...
DeployAsync: END (Failure, 0:00:01.499)
Deploy: END (Failure, 0:00:01.5)

Solution

Remove your application source code from shared folder
or
You are being signed in with my Microsoft account in windows instead of the local user account
or
Visual Studio is not able to delete the application data in your local packages folder, go to C:\Users\<YOURNAME>\AppData\Local\Packages\ folder, and delete your applications folder manually.
or
browse more solution at here
🙂

This content has 3 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

Upgrading Xamarin.Forms projects to .NET MAUI with upgrade assistant

MAUI is still in preview state, so the production apps are not recommended to upgrade to .NET MAUI. But it is important to be open to new technology, so take some time to review the update.

It’s possible that by the time you read this post, you’ll be able to convert a MAUI projects from UI, but it’s not currently an available feature for me.

What you will need

  • Windows machine
  • Visual Studio 2022 installed

Install required tools for MAUI

Open a command prompt and give out the following command:

dotnet workload install maui

If you have installed maui already, then you wont need to run this command again.

Install upgrade-assistant

There is a tool developed by Microsoft, not originally for MAUI, but because it is based on a fully extensible model, it has been made available for MAUI projects. Xamarin.Forms projects can be translated to the new version of the projects with this app:
https://dotnet.microsoft.com/en-us/platform/upgrade-assistant

dotnet tool install --global upgrade-assistant

Use the upgrade assistant

It is important to note that this application cannot independently translate Xamarin.Forms apps to MAUI. It only helps us in the upgrade process.

That’s why the app asks for constant instructions, so we can’t leave the machine running while we make coffee 🙂

Let’s change the directory of your command prompt to the directory where you store the .sln file

upgrade-assistant upgrade SolutionName.sln

Watch out for the output of the console. If everything goes well, your solution can be transformed to maui without issues.

In the header section of the console output, you will see what steps are required (or suggested) in order to complete the migration. You can decide what to do with the next step: Apply, skip, or do something else with it. If everything goes well, you will only need to press apply.

The output of the upgrade-assistant

Once you have finished the upgrade assistant process, you can see the changes. Mostly in source codes and project files.

Namespace changes

This content has 3 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.