Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 8 additions & 8 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@
</ItemGroup>
<!-- Avalonia -->
<ItemGroup Condition=" $(IsAvaloniaProject) == 'true' ">
<PackageVersion Include="Avalonia" Version="11.3.8" />
<PackageVersion Include="Avalonia.Desktop" Version="11.3.8" />
<PackageVersion Include="Avalonia.Diagnostics" Version="11.3.8" />
<PackageVersion Include="Avalonia.LinuxFramebuffer" Version="11.3.8" />
<PackageVersion Include="Avalonia.Markup.Xaml.Loader" Version="11.3.8" />
<PackageVersion Include="Avalonia.Themes.Simple" Version="11.3.8" />
<PackageVersion Include="Avalonia.Themes.Fluent" Version="11.3.8" />
<PackageVersion Include="Avalonia.Fonts.Inter" Version="11.3.8" />
<PackageVersion Include="Avalonia" Version="12.1.1" />
<PackageVersion Include="Avalonia.Desktop" Version="12.1.1" />
<PackageVersion Include="AvaloniaUI.DiagnosticsSupport" Version="2.2.2" />
<PackageVersion Include="Avalonia.LinuxFramebuffer" Version="12.1.1" />
<PackageVersion Include="Avalonia.Markup.Xaml.Loader" Version="12.1.1" />
<PackageVersion Include="Avalonia.Themes.Simple" Version="12.1.1" />
<PackageVersion Include="Avalonia.Themes.Fluent" Version="12.1.1" />
<PackageVersion Include="Avalonia.Fonts.Inter" Version="12.1.1" />
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="10.0.0" />
<PackageVersion Include="System.CodeDom" Version="8.0.0" />
</ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions e2e/Avalonia/PrismAvaloniaDemo.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@
<Project Path="../../src/Prism.Core/Prism.Core.csproj" />
<Project Path="../../src/Prism.Events/Prism.Events.csproj" />
</Folder>
<Folder Name="/Solution Items/">
<File Path="../../.gitignore" />
<File Path="../../Directory.Build.props" />
<File Path="../../Directory.Build.targets" />
<File Path="../../Directory.Packages.props" />
</Folder>
<Project Path="PrismAvaloniaDemo/PrismAvaloniaDemo.csproj" />
</Solution>
1 change: 1 addition & 0 deletions e2e/Avalonia/PrismAvaloniaDemo/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ trim_trailing_whitespace = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true

[*.sln]
indent_size = 2
Expand Down
24 changes: 17 additions & 7 deletions e2e/Avalonia/PrismAvaloniaDemo/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Data.Core;
using Avalonia.Data.Core.Plugins;
using Avalonia.Markup.Xaml;
using Prism.DryIoc;
using Prism.Ioc;
using Prism.Navigation.Regions;
using SampleApp.Services;
using SampleApp.ViewModels;
using SampleApp.Views;
using static Microsoft.IO.RecyclableMemoryStreamManager;

namespace SampleApp;

Expand All @@ -20,6 +16,17 @@ public override void Initialize()

// Required when overriding Initialize
base.Initialize();

#if DEBUG
// Replaces the old this.AttachDevTools();
// NOTE: This requires connection to, http://127.0.0.1:29414/ and some IT firewalls may block it.
// Reference: https://docs.avaloniaui.net/tools/developer-tools/attaching-to-the-remote-tool
this.AttachDeveloperTools();
////{
//// // Change the initialization key gesture (Default is F12)
//// options.Gesture = Avalonia.Input.KeyGesture.Parse("F11");
////});
#endif
}

protected override AvaloniaObject CreateShell()
Expand All @@ -29,13 +36,16 @@ protected override AvaloniaObject CreateShell()

protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
// Register your Services, Views, Dialogs, etc. here

// Services
containerRegistry.RegisterSingleton<INotificationService, NotificationService>();

// Views - Dialogs
containerRegistry.RegisterDialog<MessageBoxView, MessageBoxViewModel>();
////containerRegistry.RegisterDialogWindow<CustomDialogWindow>(nameof(CustomDialogWindow));

// Views - Region Navigation
containerRegistry.RegisterForNavigation<DashboardView, DashboardViewModel>();
containerRegistry.RegisterForNavigation<DialogSampleView, DialogSampleViewModel>();
containerRegistry.RegisterForNavigation<SettingsView, SettingsViewModel>();
containerRegistry.RegisterForNavigation<SubSettingsView, SubSettingsViewModel>();
}
Expand Down
5 changes: 3 additions & 2 deletions e2e/Avalonia/PrismAvaloniaDemo/PrismAvaloniaDemo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
<PackageReference Include="Avalonia.Desktop" />
<PackageReference Include="Avalonia.Themes.Fluent" />
<PackageReference Include="Avalonia.Fonts.Inter" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" />
<!-- Avalonia.Diagnostics is now known as, AvaloniaUI.DiagnosticsSupport. -->
<!-- Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration. -->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="AvaloniaUI.DiagnosticsSupport" />
</ItemGroup>

<ItemGroup>
Expand Down
46 changes: 34 additions & 12 deletions e2e/Avalonia/PrismAvaloniaDemo/Styles/Icons.axaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Prism.Commands;
using Prism.Dialogs;
using SampleApp.Views;

namespace SampleApp.ViewModels;

public class DialogSampleViewModel : ViewModelBase
{
private readonly IDialogService _dialog;

private string _msgBoxTitle = string.Empty;
private string _msgBoxMessage = string.Empty;
private string _msgBoxResult = string.Empty;

public DialogSampleViewModel(IDialogService dialog)
{
_dialog = dialog;

MsgBoxTitle = "Sample Dialog";
MsgBoxMessage = "Hello from the DialogSampleViewModel!";
Title = "Dialog Sample";
}

public DelegateCommand CmdShowMsgBox => new(() =>
{
var parameters = new DialogParameters
{
{ "title", MsgBoxTitle },
{ "message", MsgBoxMessage },
};

_dialog.ShowDialog(nameof(MessageBoxView), parameters, result =>
{
if (result.Result == ButtonResult.OK)
MsgBoxResult = "OK";
else if (result.Result == ButtonResult.Cancel)
MsgBoxResult = "Cancel";
});
});

public string MsgBoxMessage { get => _msgBoxMessage; set => SetProperty(ref _msgBoxMessage, value); }

public string MsgBoxResult { get => _msgBoxResult; set => SetProperty(ref _msgBoxResult, value); }

public string MsgBoxTitle { get => _msgBoxTitle; set => SetProperty(ref _msgBoxTitle, value); }
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public MainWindowViewModel(IRegionManager regionManager)
_regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(DashboardView));
});

public DelegateCommand CmdDialogSample => new(() =>
{
_regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(DialogSampleView));
});

public DelegateCommand CmdFlyoutMenu => new(() =>
{
IsPaneOpened = !IsPaneOpened;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using System.Text;
using Prism.Commands;
using Prism.Dialogs;
using Prism.Mvvm;

namespace SampleApp.ViewModels;

public class MessageBoxViewModel : BindableBase, IDialogAware
{
private string _customMessage = string.Empty;
private int _maxHeight;
private int _maxWidth;
private string _title = "Notification";

public MessageBoxViewModel()
{
Title = "Alert!";

MaxHeight = 800;
MaxWidth = 600;
}

public DelegateCommand<string> CmdResult => new DelegateCommand<string>((param) =>
{
// None = 0
// OK = 1
// Cancel = 2
// Abort = 3
// Retry = 4
// Ignore = 5
// Yes = 6
// No = 7
ButtonResult result = ButtonResult.None;

if (int.TryParse(param, out int intResult))
result = (ButtonResult)intResult;

RequestClose.Invoke(result);
});

public string CustomMessage { get => _customMessage; set => SetProperty(ref _customMessage, value); }

public int MaxHeight { get => _maxHeight; set => SetProperty(ref _maxHeight, value); }

public int MaxWidth { get => _maxWidth; set => SetProperty(ref _maxWidth, value); }

public DialogCloseListener RequestClose { get; }

public string Title { get => _title; set => SetProperty(ref _title, value); }

/// <summary>Allows the dialog to close.</summary>
/// <returns>Return true to allow closing (i.e. OK button only).</returns>
public virtual bool CanCloseDialog() => true;

public virtual void OnDialogClosed()
{
// Detach custom event handlers here, etc.
}

public void OnDialogOpened(IDialogParameters parameters)
{
var title = parameters.GetValue<string>("title");
if (!string.IsNullOrEmpty(title))
Title = title;

CustomMessage = parameters.GetValue<string>("message");
}
}
107 changes: 63 additions & 44 deletions e2e/Avalonia/PrismAvaloniaDemo/ViewModels/SubSettingsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;
using System.Collections.Generic;
using Prism.Commands;
using Prism.Navigation.Regions;
using SampleApp.Views;
Expand All @@ -6,48 +8,65 @@ namespace SampleApp.ViewModels;

public class SubSettingsViewModel : ViewModelBase
{
private readonly IRegionManager _regionManager;
private IRegionNavigationJournal? _journal;
private string _messageNumber = string.Empty;
private string _messageText = string.Empty;

public SubSettingsViewModel(IRegionManager regionManager)
{
_regionManager = regionManager;

Title = "Settings - SubView";
}

public DelegateCommand CmdNavigateBack => new DelegateCommand(() =>
{
// Go back to the previous calling page, otherwise, Dashboard.
if (_journal != null && _journal.CanGoBack)
_journal.GoBack();
else
_regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(DashboardView));
});

public string MessageNumber { get => _messageNumber; set => SetProperty(ref _messageNumber, value); }

public string MessageText { get => _messageText; set => SetProperty(ref _messageText, value); }

/// <summary>Navigation completed successfully.</summary>
/// <param name="navigationContext">Navigation context.</param>
public override void OnNavigatedTo(NavigationContext navigationContext)
{
// Used to "Go Back" to parent
_journal = navigationContext.NavigationService.Journal;

// Display our parameters
MessageText = navigationContext.Parameters["key1"].ToString() ?? "";
MessageNumber = navigationContext.Parameters["key2"].ToString() ?? "";
}

public override bool OnNavigatingTo(NavigationContext navigationContext)
{
// Navigation permission sample:
// Don't allow navigation if our keys are missing
return navigationContext.Parameters.ContainsKey("key1") &&
navigationContext.Parameters.ContainsKey("key2");
}
private readonly IRegionManager _regionManager;
private IRegionNavigationJournal? _journal;
private string _messageNumber = string.Empty;
private string _messageText = string.Empty;

public SubSettingsViewModel(IRegionManager regionManager)
{
_regionManager = regionManager;

Title = "Settings - SubView";
}

public DelegateCommand CmdNavigateBack => new DelegateCommand(() =>
{
// Go back to the previous calling page, otherwise, Dashboard.
if (_journal != null && _journal.CanGoBack)
_journal.GoBack();
else
_regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(DashboardView));
});

public string MessageNumber { get => _messageNumber; set => SetProperty(ref _messageNumber, value); }

public string MessageText { get => _messageText; set => SetProperty(ref _messageText, value); }

/// <summary>Navigation completed successfully.</summary>
/// <param name="navigationContext">Navigation context.</param>
public override void OnNavigatedTo(NavigationContext navigationContext)
{
// Used to "Go Back" to parent
_journal = navigationContext.NavigationService.Journal;

// Display our parameters
MessageText = GetKeyValueAsString(navigationContext, "key1");
MessageNumber = GetKeyValueAsString(navigationContext, "key2");

}

public override bool OnNavigatingTo(NavigationContext navigationContext)
{
// Navigation permission sample:
// Don't allow navigation if our keys are missing
return navigationContext.Parameters.ContainsKey("key1") &&
navigationContext.Parameters.ContainsKey("key2");
}

public static string GetKeyValueAsString(NavigationContext context, string targetKey, string defaultValue = "")
{
var searchList = context.Parameters;
if (searchList == null || targetKey == null)
return defaultValue;

foreach (KeyValuePair<string, object> kvp in searchList)
{
// Safe string comparison (Ordinal ignores regional culture bugs)
if (string.Equals(kvp.Key, targetKey, StringComparison.Ordinal))
return kvp.Value?.ToString() ?? defaultValue;
}

return defaultValue;
}
}
Loading
Loading