Microsoft customize example not works

Haviv Elbsz 2,151 Reputation points
2023-01-01T08:00:11.253+00:00

Hi all

https://devblogs.microsoft.com/dotnet/dotnet-maui-rc-1/#customizing-controls

The customize from Microsoft from the above link not work.

namespace RazKmoShed;  
  
public partial class App : Application  
{  
	public App()  
	{  
        InitializeComponent();  
  
#if ANDROID  
Microsoft.Maui.Handlers.EntryHandler.Mapper.ModifyMapping("NoUnderline", (h, v) =>  
{  
    h.PlatformView.BackgroundTintList = ColorStateList.ValueOf(Colors.Transparent.ToPlatform());  
});  
#endif  
  
        MainPage = new AppShell();  
  
	}  
}   
  

Thank you
275274-screenshot-2023-01-01-095819.jpg

Developer technologies | .NET | .NET MAUI
{count} votes

Answer accepted by question author
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,451 Reputation points Microsoft External Staff
    2023-01-02T09:06:25.637+00:00

    Hello,

    The link you mentioned is old, you can refer to the latest doc - .NET MAUI control customization with handlers - .NET MAUI | Microsoft Learn
    ModifyMapping can modify an existing mapping, it looks like NoUnderline didn't exist. And this ModifyMapping method has three arguments for the second parameter, you set only two objects, see PropertyMapperExtensions.ModifyMapping<TVirtualView,TViewHandler> Method
    method
    Action<TViewHandler,TVirtualView,Action<IElementHandler,IElement>>
    The modified method to call when the property is updated.

    You can refer to the following code and using Microsoft.Maui.Platform; as you said:

    #if ANDROID  
            Microsoft.Maui.Handlers.EntryHandler.Mapper.ModifyMapping("NoUnderline", (h, v, e) =>  
            {  
                h.PlatformView.BackgroundTintList = ColorStateList.ValueOf(Colors.Transparent.ToPlatform());  
            });  
    
    #endif  
    

    but my background color set in xaml is changed to white

    You could try to customize a drawable under Platform/Android/Resources and set h.PlatformView.Background.

    Best Regards,
    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.