Skip to content

Commit

Permalink
Use HyperlinkButton.NavigateUri instead of custom commands
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-lerch committed Jul 31, 2024
1 parent d065c6a commit e5aa517
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 30 deletions.
18 changes: 1 addition & 17 deletions src/Vocup/ViewModels/LicensesViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
using ReactiveUI;
using System;
using System.Collections.Generic;
using System.Reactive;
using System.Reactive.Linq;
using System.Collections.Generic;

namespace Vocup.ViewModels;

public class LicensesViewModel
{
public LicensesViewModel()
{
NavigateToUri = ReactiveCommand.Create<string>(async uri =>
{
await LaunchUri.Handle(new Uri(uri));
});
}

public ReactiveCommand<string, Unit> NavigateToUri { get; }

public Interaction<Uri, bool> LaunchUri { get; } = new();

public List<Component> Components { get; } = [
new()
{
Expand Down
3 changes: 1 addition & 2 deletions src/Vocup/Views/LicensesControl.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
Grid.Column="0"
Classes="link"
Content="{Binding Name}"
Command="{Binding #control.ViewModel.NavigateToUri}"
CommandParameter="{Binding Url}"
NavigateUri="{Binding Url}"
ToolTip.Tip="{Binding Url}"
/>
<TextBlock Grid.Column="1" Text="{Binding License}" FontSize="12" />
Expand Down
12 changes: 1 addition & 11 deletions src/Vocup/Views/LicensesControl.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
using Avalonia.Controls;
using Avalonia.ReactiveUI;
using ReactiveUI;
using Vocup.ViewModels;

namespace Vocup.Views;

public partial class LicensesControl : ReactiveUserControl<LicensesViewModel>
public partial class LicensesControl : UserControl
{
public LicensesControl()
{
InitializeComponent();

this.WhenActivated(d => d(ViewModel.LaunchUri.RegisterHandler(async interaction =>
{
var topLevel = TopLevel.GetTopLevel(this);
bool success = await topLevel.Launcher.LaunchUriAsync(interaction.Input);
interaction.SetOutput(success);
})));
}
}

0 comments on commit e5aa517

Please sign in to comment.