144 lines
4.6 KiB
C#
144 lines
4.6 KiB
C#
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|||
|
|
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
|
|||
|
|
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
|
|||
|
|
// All Rights Reserved.
|
|||
|
|
|
|||
|
|
using System.Diagnostics.CodeAnalysis;
|
|||
|
|
|
|||
|
|
using WPFluent.Extensions;
|
|||
|
|
using WPFluent.Gallery.Controls;
|
|||
|
|
using WPFluent.Gallery.ControlsLookup;
|
|||
|
|
using WPFluent.Gallery.Models;
|
|||
|
|
using WPFluent.Gallery.Views.Pages;
|
|||
|
|
|
|||
|
|
namespace WPFluent.Gallery.ViewModels.Pages;
|
|||
|
|
|
|||
|
|
public partial class DialogsAndFlyoutsViewModel : ViewModel
|
|||
|
|
{
|
|||
|
|
[ObservableProperty]
|
|||
|
|
private ICollection<NavigationCard> _navigationCards = new ObservableCollection<NavigationCard>(
|
|||
|
|
ControlPages
|
|||
|
|
.FromNamespace(typeof(DialogsAndFlyoutsPage).Namespace!)
|
|||
|
|
.Select(x => new NavigationCard()
|
|||
|
|
{
|
|||
|
|
Name = x.Name,
|
|||
|
|
Icon = x.Icon,
|
|||
|
|
Description = x.Description,
|
|||
|
|
PageType = x.PageType,
|
|||
|
|
})
|
|||
|
|
);
|
|||
|
|
[SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "relay command")]
|
|||
|
|
[RelayCommand]
|
|||
|
|
private void OnOpenStandardMessageBox(object sender)
|
|||
|
|
{
|
|||
|
|
_ = System.Windows.MessageBox.Show("Something about to happen", "I can feel it");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "relay command")]
|
|||
|
|
[RelayCommand]
|
|||
|
|
private async Task OnOpenCustomMessageBox(object sender)
|
|||
|
|
{
|
|||
|
|
var uiMessageBox = new WPFluent.Controls.MessageWindow
|
|||
|
|
{
|
|||
|
|
Title = "WPF UI Message Box",
|
|||
|
|
Content =
|
|||
|
|
"Never gonna give you up, never gonna let you down Never gonna run around and desert you Never gonna make you cry, never gonna say goodbye",
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
_ = await uiMessageBox.ShowDialogAsync();
|
|||
|
|
}
|
|||
|
|
#region Snackbar
|
|||
|
|
private ControlAppearance _snackbarAppearance = ControlAppearance.Secondary;
|
|||
|
|
|
|||
|
|
[ObservableProperty]
|
|||
|
|
private int _snackbarTimeout = 2;
|
|||
|
|
|
|||
|
|
private int _snackbarAppearanceComboBoxSelectedIndex = 1;
|
|||
|
|
|
|||
|
|
public int SnackbarAppearanceComboBoxSelectedIndex
|
|||
|
|
{
|
|||
|
|
get => _snackbarAppearanceComboBoxSelectedIndex;
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
_ = SetProperty(ref _snackbarAppearanceComboBoxSelectedIndex, value);
|
|||
|
|
UpdateSnackbarAppearance(value);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ISnackbarService snackbarService;
|
|||
|
|
[RelayCommand]
|
|||
|
|
private void OnOpenSnackbar(object sender)
|
|||
|
|
{
|
|||
|
|
snackbarService.Show(
|
|||
|
|
"Don't Blame Yourself.",
|
|||
|
|
"No Witcher's Ever Died In His Bed.",
|
|||
|
|
_snackbarAppearance,
|
|||
|
|
new SymbolIcon(SymbolRegular.Fluent24),
|
|||
|
|
TimeSpan.FromSeconds(SnackbarTimeout)
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void UpdateSnackbarAppearance(int appearanceIndex)
|
|||
|
|
{
|
|||
|
|
_snackbarAppearance = appearanceIndex switch
|
|||
|
|
{
|
|||
|
|
1 => ControlAppearance.Secondary,
|
|||
|
|
2 => ControlAppearance.Info,
|
|||
|
|
3 => ControlAppearance.Success,
|
|||
|
|
4 => ControlAppearance.Caution,
|
|||
|
|
5 => ControlAppearance.Danger,
|
|||
|
|
6 => ControlAppearance.Light,
|
|||
|
|
7 => ControlAppearance.Dark,
|
|||
|
|
8 => ControlAppearance.Transparent,
|
|||
|
|
_ => ControlAppearance.Primary,
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
[ObservableProperty]
|
|||
|
|
private bool _isFlyoutOpen = false;
|
|||
|
|
|
|||
|
|
[RelayCommand]
|
|||
|
|
private void OnButtonClick(object sender)
|
|||
|
|
{
|
|||
|
|
if (!IsFlyoutOpen)
|
|||
|
|
{
|
|||
|
|
IsFlyoutOpen = true;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
#region ContentDialog
|
|||
|
|
IContentDialogService contentDialogService;
|
|||
|
|
[ObservableProperty]
|
|||
|
|
private string _dialogResultText = string.Empty;
|
|||
|
|
|
|||
|
|
[RelayCommand]
|
|||
|
|
private async Task OnShowDialog(object content)
|
|||
|
|
{
|
|||
|
|
ContentDialogResult result = await contentDialogService.ShowSimpleDialogAsync(
|
|||
|
|
new SimpleContentDialogCreateOptions()
|
|||
|
|
{
|
|||
|
|
Title = "Save your work?",
|
|||
|
|
Content = content,
|
|||
|
|
PrimaryButtonText = "Save",
|
|||
|
|
SecondaryButtonText = "Don't Save",
|
|||
|
|
CloseButtonText = "Cancel",
|
|||
|
|
}
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
DialogResultText = result switch
|
|||
|
|
{
|
|||
|
|
ContentDialogResult.Primary => "User saved their work",
|
|||
|
|
ContentDialogResult.Secondary => "User did not save their work",
|
|||
|
|
_ => "User cancelled the dialog",
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[RelayCommand]
|
|||
|
|
private async Task OnShowSignInContentDialog()
|
|||
|
|
{
|
|||
|
|
var termsOfUseContentDialog = new TermsOfUseContentDialog(contentDialogService.GetDialogHost());
|
|||
|
|
|
|||
|
|
_ = await termsOfUseContentDialog.ShowAsync();
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
}
|