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
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Wpf.Ui.Contracts;
using Wpf.Ui.Controls;
using Wpf.Ui.Controls.IconElements;
using SymbolIcon = Wpf.Ui.Controls.IconElements.SymbolIcon;

namespace Wpf.Ui.Gallery.ViewModels.Pages.DialogsAndFlyouts;

public partial class SnackbarViewModel : ObservableObject
{
private readonly ISnackbarService _snackbarService;
public SnackbarViewModel(ISnackbarService snackbarService)
{
_snackbarService = snackbarService;
}

private readonly ISnackbarService _snackbarService;
private ControlAppearance _snackbarAppearance = ControlAppearance.Secondary;

[ObservableProperty]
private int _snackbarTimeout = 2000;
private int _snackbarTimeout = 2;

private int _snackbarAppearanceComboBoxSelectedIndex = 1;

Expand All @@ -33,16 +33,11 @@ public int SnackbarAppearanceComboBoxSelectedIndex
}
}

public SnackbarViewModel(ISnackbarService snackbarService)
{
_snackbarService = snackbarService;
}

[RelayCommand]
private void OnOpenSnackbar(object sender)
{
_snackbarService.Timeout = SnackbarTimeout;
_snackbarService.Show("Don't Blame Yourself.", "No Witcher's Ever Died In His Bed.", new SymbolIcon(SymbolRegular.Fluent24), _snackbarAppearance);
_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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@
AutoToolTipPlacement="BottomRight"
AutoToolTipPrecision="0"
IsSnapToTickEnabled="True"
Maximum="5000"
Minimum="200"
TickFrequency="200"
Maximum="5"
Minimum="1"
TickFrequency="1"
TickPlacement="BottomRight"
Value="{Binding ViewModel.SnackbarTimeout, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:SnackbarPage}, Mode=TwoWay}" />
</Grid>
Expand Down
4 changes: 2 additions & 2 deletions src/Wpf.Ui.Gallery/Views/Windows/EditorWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@
</StatusBar>
</Grid>

<ui:Snackbar
<!--<ui:Snackbar
x:Name="RootSnackbar"
Grid.Row="0"
Timeout="5000" />
Timeout="5000" />-->

<!--<ui:Dialog x:Name="ActionDialog">
<Grid>
Expand Down
2 changes: 1 addition & 1 deletion src/Wpf.Ui.Gallery/Views/Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
</ui:NavigationView.AutoSuggestBox>
<ui:NavigationView.ContentOverlay>
<Grid>
<ui:Snackbar x:Name="RootSnackbar" />
<ui:SnackbarPresenter x:Name="SnackbarPresenter" />
</Grid>
</ui:NavigationView.ContentOverlay>
</ui:NavigationView>
Expand Down
2 changes: 1 addition & 1 deletion src/Wpf.Ui.Gallery/Views/Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public MainWindow(MainWindowViewModel viewModel, INavigationService navigationSe

InitializeComponent();

snackbarService.SetSnackbarControl(RootSnackbar);
snackbarService.SetSnackbarPresenter(SnackbarPresenter);
navigationService.SetNavigationControl(NavigationView);
contentDialogService.SetContentPresenter(RootContentDialog);

Expand Down
19 changes: 0 additions & 19 deletions src/Wpf.Ui/Common/RoutedSnackbarEvent.cs

This file was deleted.

120 changes: 18 additions & 102 deletions src/Wpf.Ui/Contracts/ISnackbarService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,127 +3,43 @@
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

using System.Threading.Tasks;
using Wpf.Ui.Common;
using System;
using System.Windows.Controls;
using Wpf.Ui.Controls;
using Wpf.Ui.Controls.IconElements;
using Wpf.Ui.Controls.SnackbarControl;

namespace Wpf.Ui.Contracts;

/// <summary>
/// Represents a contract with the service that provides global <see cref="ISnackbarControl"/>.
/// Represents a contract with the service that provides global <see cref="Snackbar"/>.
/// </summary>
public interface ISnackbarService
{
/// <summary>
/// Gets the information whether the <see cref="ISnackbarControl"/> is visible.
/// Gets or sets a time for which the <see cref="Snackbar"/> should be visible. (By default 2 seconds)
/// </summary>
bool IsShown { get; }
TimeSpan DefaultTimeOut { get; set; }

/// <summary>
/// Gets or sets a time for which the <see cref="ISnackbarControl"/> should be visible.
/// Sets the <see cref="SnackbarPresenter"/>
/// </summary>
int Timeout { get; set; }
/// <param name="contentPresenter"></param>
void SetSnackbarPresenter(SnackbarPresenter contentPresenter);

/// <summary>
/// Sets the <see cref="ISnackbarControl"/> used in the service. Typically this control is defined in the main window.
/// Provides direct access to the <see cref="ContentPresenter"/>
/// </summary>
void SetSnackbarControl(ISnackbarControl snackbar);

/// <summary>
/// Gets the <see cref="ISnackbarControl"/> used in the service.
/// </summary>
ISnackbarControl GetSnackbarControl();

/// <summary>
/// Shows the snackbar. If it is already visible, firstly hides it for a moment, changes its content, and then shows it again.
/// </summary>
/// <returns><see langword="true"/> if invocation of <see langword="async"/> method succeeded, Exception otherwise.</returns>
bool Show();

/// <summary>
/// Shows the snackbar. If it is already visible, firstly hides it for a moment, changes its content, and then shows it again.
/// </summary>
/// <param name="title"><see cref="ISnackbarControl.Title"/> at the top of the snackbar.</param>
/// <returns><see langword="true"/> if invocation of <see langword="async"/> method succeeded, Exception otherwise.</returns>
bool Show(string title);

/// <summary>
/// Shows the snackbar. If it is already visible, firstly hides it for a moment, changes its content, and then shows it again.
/// </summary>
/// <param name="title"><see cref="ISnackbarControl.Title"/> at the top of the snackbar.</param>
/// <param name="message"><see cref="ISnackbarControl.Message"/> in the content of the snackbar.</param>
/// <returns><see langword="true"/> if invocation of <see langword="async"/> method succeeded, Exception otherwise.</returns>
bool Show(string title, string message);
/// <returns></returns>
SnackbarPresenter GetSnackbarPresenter();

/// <summary>
/// Shows the snackbar. If it is already visible, firstly hides it for a moment, changes its content, and then shows it again.
/// </summary>
/// <param name="title"><see cref="ISnackbarControl.Title"/> at the top of the snackbar.</param>
/// <param name="message"><see cref="ISnackbarControl.Message"/> in the content of the snackbar.</param>
/// <param name="icon">Icon on the left.</param>
/// <returns><see langword="true"/> if invocation of <see langword="async"/> method succeeded, Exception otherwise.</returns>
bool Show(string title, string message, IconElement icon);

/// <summary>
/// Shows the snackbar. If it is already visible, firstly hides it for a moment, changes its content, and then shows it again.
/// </summary>
/// <param name="title"><see cref="ISnackbarControl.Title"/> at the top of the snackbar.</param>
/// <param name="message"><see cref="ISnackbarControl.Message"/> in the content of the snackbar.</param>
/// <param name="icon"><see cref="IIconControl.Icon"/>Icon on the left.</param>
/// <param name="appearance"><see cref="IAppearanceControl.Appearance"/> of the snackbar.</param>
/// <returns><see langword="true"/> if invocation of <see langword="async"/> method succeeded, Exception otherwise.</returns>
bool Show(string title, string message, IconElement icon, ControlAppearance appearance);

/// <summary>
/// Asynchronously shows the snackbar. If it is already visible, firstly hides it for a moment, changes its content, and then shows it again.
/// </summary>
/// <returns><see langword="true"/> if the operation was successful.</returns>
Task<bool> ShowAsync();

/// <summary>
/// Asynchronously shows the snackbar. If it is already visible, firstly hides it for a moment, changes its content, and then shows it again.
/// </summary>
/// <param name="title"><see cref="ISnackbarControl.Title"/> at the top of the snackbar.</param>
/// <returns><see langword="true"/> if the operation was successful.</returns>
Task<bool> ShowAsync(string title);

/// <summary>
/// Asynchronously shows the snackbar. If it is already visible, firstly hides it for a moment, changes its content, and then shows it again.
/// </summary>
/// <param name="title"><see cref="ISnackbarControl.Title"/> at the top of the snackbar.</param>
/// <param name="message"><see cref="ISnackbarControl.Message"/> in the content of the snackbar.</param>
/// <returns><see langword="true"/> if the operation was successful.</returns>
Task<bool> ShowAsync(string title, string message);

/// <summary>
/// Asynchronously shows the snackbar. If it is already visible, firstly hides it for a moment, changes its content, and then shows it again.
/// </summary>
/// <param name="title"><see cref="ISnackbarControl.Title"/> at the top of the snackbar.</param>
/// <param name="message"><see cref="ISnackbarControl.Message"/> in the content of the snackbar.</param>
/// <param name="icon"><see cref="IIconControl.Icon"/> on the left.</param>
/// <returns><see langword="true"/> if the operation was successful.</returns>
Task<bool> ShowAsync(string title, string message, IconElement icon);

/// <summary>
/// Asynchronously shows the snackbar. If it is already visible, firstly hides it for a moment, changes its content, and then shows it again.
/// </summary>
/// <param name="title"><see cref="ISnackbarControl.Title"/> at the top of the snackbar.</param>
/// <param name="message"><see cref="ISnackbarControl.Message"/> in the content of the snackbar.</param>
/// <param name="icon"><see cref="IIconControl.Icon"/> on the left.</param>
/// <param name="appearance"><see cref="IAppearanceControl.Appearance"/> of the snackbar.</param>
/// <returns><see langword="true"/> if the operation was successful.</returns>
Task<bool> ShowAsync(string title, string message, IconElement icon, ControlAppearance appearance);

/// <summary>
/// Hides the snackbar based on the selected animation, if control is visible.
/// </summary>
/// <returns><see langword="true"/> if invocation of <see langword="async"/> method succeeded, Exception otherwise.</returns>
bool Hide();

/// <summary>
/// Asynchronously hides the snackbar based on the selected animation, if control is visible.
/// </summary>
/// <returns><see langword="true"/> if the operation was successful.</returns>
Task<bool> HideAsync();
/// <param name="title"></param>
/// <param name="message"></param>
/// <param name="appearance"></param>
/// <param name="icon"></param>
/// <param name="timeout"></param>
void Show(string title, string message, ControlAppearance appearance = ControlAppearance.Secondary, IconElement? icon = null, TimeSpan timeout = default);
}
Loading