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 2 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 2 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.Android get resource id without ResourceManager.

If calling ResourceManager.GetResource(“resourceName”) doesn’t work because the framework doesn’t return the resource you want, you can bypass it with the following code snippet:

            string audioFileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(audiofile);
            int audioResourceId = (int)typeof(Resource.Raw).GetField(audioFileNameWithoutExtension).GetValue(null);
            Android.Net.Uri audioUri = Android.Net.Uri.Parse(ContentResolver.SchemeAndroidResource + "://" + Application.Context.PackageName + "/" + audioResourceId);

            channel.SetSound(audioUri, audioAttributes);

I used this code snippet to set a custom push notification sound

This content has 2 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.

Sourcetree + Azure DevOps error

If you are facing the issue with Sourcetree, that you can not push to your Azure DevOps repository, because it fails with the following error:

Pushing to https://bitfoxhungary.visualstudio.com/someProject/_git/someProject
fatal: unable to access 'https://bitfoxhungary.visualstudio.com/someProject/_git/someProject/': The requested URL returned error: 403

Copy the URL returned by the error, and browse it with a web browser.

If needed, provide your login credentials in the browser, then try again.

This content has 2 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 2 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.