Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReactiveUI.Avalonia migration #3936

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions integrationtests/IntegrationTests.All.sln
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReactiveUI.Uwp", "..\src\Re
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReactiveUI.AndroidX", "..\src\ReactiveUI.AndroidX\ReactiveUI.AndroidX.csproj", "{824088E4-A1D2-4B71-843E-873D351073C8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntegrationTests.Avalonia", "IntegrationTests.Avalonia\IntegrationTests.Avalonia.csproj", "{556E134B-BA44-4885-A5F9-FB2D668F30A2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReactiveUI.Avalonia", "..\src\ReactiveUI.Avalonia\ReactiveUI.Avalonia.csproj", "{67F3CF51-1448-468E-BF86-4769F0EDF581}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Ad-Hoc|Any CPU = Ad-Hoc|Any CPU
Expand Down Expand Up @@ -1088,6 +1092,102 @@ Global
{824088E4-A1D2-4B71-843E-873D351073C8}.Release|x64.Build.0 = Release|Any CPU
{824088E4-A1D2-4B71-843E-873D351073C8}.Release|x86.ActiveCfg = Release|Any CPU
{824088E4-A1D2-4B71-843E-873D351073C8}.Release|x86.Build.0 = Release|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Ad-Hoc|ARM.Build.0 = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Ad-Hoc|x64.Build.0 = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Ad-Hoc|x86.Build.0 = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.AppStore|Any CPU.Build.0 = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.AppStore|ARM.ActiveCfg = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.AppStore|ARM.Build.0 = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.AppStore|iPhone.Build.0 = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.AppStore|x64.ActiveCfg = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.AppStore|x64.Build.0 = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.AppStore|x86.ActiveCfg = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.AppStore|x86.Build.0 = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Debug|ARM.ActiveCfg = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Debug|ARM.Build.0 = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Debug|iPhone.Build.0 = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Debug|x64.ActiveCfg = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Debug|x64.Build.0 = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Debug|x86.ActiveCfg = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Debug|x86.Build.0 = Debug|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Release|Any CPU.Build.0 = Release|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Release|ARM.ActiveCfg = Release|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Release|ARM.Build.0 = Release|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Release|iPhone.ActiveCfg = Release|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Release|iPhone.Build.0 = Release|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Release|x64.ActiveCfg = Release|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Release|x64.Build.0 = Release|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Release|x86.ActiveCfg = Release|Any CPU
{556E134B-BA44-4885-A5F9-FB2D668F30A2}.Release|x86.Build.0 = Release|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Ad-Hoc|ARM.Build.0 = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Ad-Hoc|x64.Build.0 = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Ad-Hoc|x86.Build.0 = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.AppStore|Any CPU.Build.0 = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.AppStore|ARM.ActiveCfg = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.AppStore|ARM.Build.0 = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.AppStore|iPhone.Build.0 = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.AppStore|x64.ActiveCfg = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.AppStore|x64.Build.0 = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.AppStore|x86.ActiveCfg = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.AppStore|x86.Build.0 = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Debug|Any CPU.Build.0 = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Debug|ARM.ActiveCfg = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Debug|ARM.Build.0 = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Debug|iPhone.Build.0 = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Debug|x64.ActiveCfg = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Debug|x64.Build.0 = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Debug|x86.ActiveCfg = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Debug|x86.Build.0 = Debug|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Release|Any CPU.ActiveCfg = Release|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Release|Any CPU.Build.0 = Release|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Release|ARM.ActiveCfg = Release|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Release|ARM.Build.0 = Release|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Release|iPhone.ActiveCfg = Release|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Release|iPhone.Build.0 = Release|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Release|x64.ActiveCfg = Release|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Release|x64.Build.0 = Release|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Release|x86.ActiveCfg = Release|Any CPU
{67F3CF51-1448-468E-BF86-4769F0EDF581}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -1101,6 +1201,7 @@ Global
{E6284535-0B6E-42AA-9113-5230AB09E8E6} = {34A7ABF0-30C6-48EA-94F0-8B116E995464}
{7B5A4E3B-8706-4D5B-B979-C5E39289CE17} = {34A7ABF0-30C6-48EA-94F0-8B116E995464}
{824088E4-A1D2-4B71-843E-873D351073C8} = {34A7ABF0-30C6-48EA-94F0-8B116E995464}
{67F3CF51-1448-468E-BF86-4769F0EDF581} = {34A7ABF0-30C6-48EA-94F0-8B116E995464}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EDE6B0FD-3EF7-49C4-AF1D-E7485C1FEFAF}
Expand Down
8 changes: 8 additions & 0 deletions integrationtests/IntegrationTests.Avalonia/App.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="IntegrationTests.Avalonia.App"
RequestedThemeVariant="Default">
<Application.Styles>
<FluentTheme />
</Application.Styles>
</Application>
28 changes: 28 additions & 0 deletions integrationtests/IntegrationTests.Avalonia/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;

namespace IntegrationTests.Avalonia;

internal partial class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}

public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow();
}

base.OnFrameworkInitializationCompleted();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFrameworks>net8.0</TargetFrameworks>
<Description>Avalonia specific example of IntegrationTests</Description>
<PackageId>IntegrationTests.Avalonia</PackageId>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.2.2" />
<PackageReference Include="Avalonia.Desktop" Version="11.2.2" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.2" />
<PackageReference Include="MessageBox.Avalonia" Version="3.2.0" />
<ProjectReference Include="..\..\src\ReactiveUI.Avalonia\ReactiveUI.Avalonia.csproj" />
<ProjectReference Include="..\IntegrationTests.Shared\IntegrationTests.Shared.csproj" />
</ItemGroup>
</Project>
45 changes: 45 additions & 0 deletions integrationtests/IntegrationTests.Avalonia/LoginControl.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<rxui:ReactiveUserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:rxui="http://reactiveui.net"
x:TypeArguments="vms:LoginViewModel"
x:Class="IntegrationTests.Avalonia.LoginControl"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:vms="using:IntegrationTests.Shared"
mc:Ignorable="d">

<Grid>

<TextBox x:Name="Username"
Text="Username"
HorizontalAlignment="Left"
Height="23" Margin="10,70,0,0"
TextWrapping="Wrap"
VerticalAlignment="Top"
Width="175"/>

<TextBox x:Name="Password"
PasswordChar="*"
HorizontalAlignment="Left"
Height="23"
Margin="10,110,0,0"
VerticalAlignment="Top"
Width="175"/>

<Button x:Name="Login"
Content="Login"
HorizontalAlignment="Left"
Margin="10,156,0,0"
VerticalAlignment="Top"
Width="78"/>

<Button x:Name="Cancel"
Content="Cancel"
HorizontalAlignment="Left"
Margin="108,156,0,0"
VerticalAlignment="Top"
Width="77"/>

</Grid>

</rxui:ReactiveUserControl>
63 changes: 63 additions & 0 deletions integrationtests/IntegrationTests.Avalonia/LoginControl.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using IntegrationTests.Shared;
using ReactiveUI;
using ReactiveUI.Avalonia;

namespace IntegrationTests.Avalonia;

/// <summary>
/// Interaction logic for LoginControl.xaml.
/// </summary>
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public partial class LoginControl : ReactiveUserControl<LoginViewModel>
{
/// <summary>
/// Initializes a new instance of the <see cref="LoginControl"/> class.
/// </summary>
public LoginControl()
{
InitializeComponent();

ViewModel = new LoginViewModel(RxApp.MainThreadScheduler);

this
.WhenActivated(
disposables =>
{
this
.Bind(ViewModel, vm => vm.UserName, v => v.Username.Text)
.DisposeWith(disposables);
this
.Bind(ViewModel, vm => vm.Password, v => v.Password.Text)
.DisposeWith(disposables);
this
.BindCommand(ViewModel, vm => vm.Login, v => v.Login)
.DisposeWith(disposables);
this
.BindCommand(ViewModel, vm => vm.Cancel, v => v.Cancel)
.DisposeWith(disposables);

ViewModel
.Login
.SelectMany(
result =>
{
if (result)
{
return this.ShowMessage("Login Successful", "Welcome!");
}

return this.ShowMessage("Login Failed", "Ah, ah, ah, you didn't say the magic word!");
})
.Subscribe()
.DisposeWith(disposables);
});
}
}
13 changes: 13 additions & 0 deletions integrationtests/IntegrationTests.Avalonia/MainWindow.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="IntegrationTests.Avalonia.MainWindow"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="using:IntegrationTests.Avalonia"
mc:Ignorable="d"
Height="227"
Width="202">

<local:LoginControl />

</Window>
17 changes: 17 additions & 0 deletions integrationtests/IntegrationTests.Avalonia/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using Avalonia.Controls;

namespace IntegrationTests.Avalonia;

[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
27 changes: 27 additions & 0 deletions integrationtests/IntegrationTests.Avalonia/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;
using Avalonia;
using ReactiveUI.Avalonia;

namespace IntegrationTests.Avalonia;

internal static class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);

// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.UseReactiveUI()
.LogToTrace();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;
using System.Reactive.Threading.Tasks;
using Avalonia.Controls;
using MsBox.Avalonia;
using MsBox.Avalonia.Enums;

namespace IntegrationTests.Avalonia;

/// <summary>
/// Extension methods associated with the UserControl class.
/// </summary>
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public static class UserControlExtensions
{
/// <summary>
/// Shows a message to the user, and have the results wrapped in a observable.
/// </summary>
/// <param name="this">The user control that hosts the message box.</param>
/// <param name="title">The title of the message box.</param>
/// <param name="message">The message to show to the user.</param>
/// <returns>An observable of the result from the message box.</returns>
public static IObservable<ButtonResult> ShowMessage(
this UserControl @this,
string title,
string message)
{
var window = (Window)TopLevel.GetTopLevel(@this)!;
var box = MessageBoxManager
.GetMessageBoxStandard(title, message);
return box.ShowWindowDialogAsync(window).ToObservable();
}
}
1 change: 1 addition & 0 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<PackageVersion Include="Xamarin.AndroidX.Legacy.Support.Core.UI" Version="1.0.0.29" />
<PackageVersion Include="Xamarin.Google.Android.Material" Version="1.11.0.2" />
<PackageVersion Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.8.4.1" />
<PackageVersion Include="Avalonia" Version="11.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(UseMaui)' != 'true'">
<PackageVersion Include="Microsoft.WindowsAppSDK" Version="1.5.240802000" />
Expand Down
Loading
Loading