Search code examples
.net-6.0visual-studio-2022maui-blazor

How to know the running Blazor MAUI platform at execution time


I want use differents components of UI for MAUI Blazor APP when its running in differents SOs. I meant, one custom component if its running on Android and other if it's running in Windows (due to well document webview bug when you try to use html selec in blazor maui for windows). There is some way to do this?, #if flag not semmeed to be work and i m using display size until now, but should be a better way. Thanks.


Solution

  • Yes you can use Microsoft.Maui.Essentials.DeviceInfo which contains Platform as a property. So you can do for example:

    @if (DeviceInfo.Platform == DevicePlatform.iOS && DeviceInfo.Platform == DevicePlatform.Android)
    {
         <select></select>
    }
    else if (DeviceInfo.Platform == DevicePlatform.UWP)
    {
        <CustomSelect />         
    }
    else
    {
                
    }