4 changed files with 94 additions and 4 deletions
@ -0,0 +1,12 @@ |
|||
<UserControl x:Class="ControlCatalog.Pages.PlatformInfoPage" |
|||
xmlns="https://github.com/avaloniaui" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
|||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
|||
d:DesignHeight="800" |
|||
d:DesignWidth="400" |
|||
mc:Ignorable="d"> |
|||
<StackPanel> |
|||
<TextBlock Text="{Binding PlatformInfo}" /> |
|||
</StackPanel> |
|||
</UserControl> |
|||
@ -0,0 +1,21 @@ |
|||
using Avalonia; |
|||
using Avalonia.Controls; |
|||
using Avalonia.Markup.Xaml; |
|||
using ControlCatalog.ViewModels; |
|||
|
|||
namespace ControlCatalog.Pages |
|||
{ |
|||
public class PlatformInfoPage : UserControl |
|||
{ |
|||
public PlatformInfoPage() |
|||
{ |
|||
this.InitializeComponent(); |
|||
DataContext = new PlatformInformationViewModel(); |
|||
} |
|||
|
|||
private void InitializeComponent() |
|||
{ |
|||
AvaloniaXamlLoader.Load(this); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,54 @@ |
|||
using Avalonia; |
|||
using Avalonia.Platform; |
|||
using MiniMvvm; |
|||
|
|||
namespace ControlCatalog.ViewModels; |
|||
#nullable enable |
|||
|
|||
public class PlatformInformationViewModel : ViewModelBase |
|||
{ |
|||
public PlatformInformationViewModel() |
|||
{ |
|||
var runtimeInfo = AvaloniaLocator.Current.GetService<IRuntimePlatform>()?.GetRuntimeInfo(); |
|||
|
|||
if (runtimeInfo is { } info) |
|||
{ |
|||
if (info.IsBrowser) |
|||
{ |
|||
if (info.IsDesktop) |
|||
{ |
|||
PlatformInfo = "Platform: Desktop (browser)"; |
|||
} |
|||
else if (info.IsMobile) |
|||
{ |
|||
PlatformInfo = "Platform: Mobile (browser)"; |
|||
} |
|||
else |
|||
{ |
|||
PlatformInfo = "Platform: Unknown (browser) - please report"; |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
if (info.IsDesktop) |
|||
{ |
|||
PlatformInfo = "Platform: Desktop (native)"; |
|||
} |
|||
else if (info.IsMobile) |
|||
{ |
|||
PlatformInfo = "Platform: Mobile (native)"; |
|||
} |
|||
else |
|||
{ |
|||
PlatformInfo = "Platform: Unknown (native) - please report"; |
|||
} |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
|
|||
} |
|||
} |
|||
|
|||
public string PlatformInfo { get; } |
|||
} |
|||
Loading…
Reference in new issue