user3863505
user3863505

Reputation: 23

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.

Upvotes: 0

Views: 1017

Answers (2)

IceCode
IceCode

Reputation: 1751

You can install the following NuGet package which adds a Blazor component that can detect browser types, browser versions, device types and lots of other useful user agent information's.

nuget: https://www.nuget.org/packages/PSC.Blazor.Components.BrowserDetect/

GitHub: https://github.com/erossini/BlazorBrowserDetect

Upvotes: -1

ScottexBoy
ScottexBoy

Reputation: 610

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
{
            
}

Upvotes: 1

Related Questions