未验证 提交 93c95665 编写于 作者: P pomianowski

Optional parameters are not optional in C#

上级 bfae681b
......@@ -22,28 +22,102 @@ public interface ISnackbarService
/// <summary>
/// Sets the <see cref="SnackbarPresenter"/>
/// </summary>
/// <param name="contentPresenter"></param>
/// <param name="contentPresenter"><see cref="ContentPresenter"/> inside of which the snackbar will be placed. The new <see cref="Snackbar"/> will replace the current <see cref="ContentPresenter.Content"/>.</param>
void SetSnackbarPresenter(SnackbarPresenter contentPresenter);
/// <summary>
/// Provides direct access to the <see cref="ContentPresenter"/>
/// </summary>
/// <returns></returns>
/// <returns><see cref="Snackbar"/> currently in use.</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"></param>
/// <param name="message"></param>
/// <param name="appearance"></param>
/// <param name="icon"></param>
/// <param name="timeout"></param>
/// <param name="title">Name displayed on top of snackbar.</param>
/// <param name="message">Message inside the snackbar.</param>
void Show(
string title,
string message
);
/// <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">Name displayed on top of snackbar.</param>
/// <param name="message">Message inside the snackbar.</param>
/// <param name="appearance">Display style.</param>
void Show(
string title,
string message,
ControlAppearance appearance
);
/// <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">Name displayed on top of snackbar.</param>
/// <param name="message">Message inside the snackbar.</param>
/// <param name="icon">Additional icon on the left.</param>
void 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">Name displayed on top of snackbar.</param>
/// <param name="message">Message inside the snackbar.</param>
/// <param name="timeout">The time after which the snackbar should disappear.</param>
void Show(
string title,
string message,
TimeSpan timeout
);
/// <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">Name displayed on top of snackbar.</param>
/// <param name="message">Message inside the snackbar.</param>
/// <param name="appearance">Display style.</param>
/// <param name="timeout">The time after which the snackbar should disappear.</param>
void Show(
string title,
string message,
ControlAppearance appearance,
TimeSpan timeout
);
/// <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">Name displayed on top of snackbar.</param>
/// <param name="message">Message inside the snackbar.</param>
/// <param name="icon">Additional icon on the left.</param>
/// <param name="timeout">The time after which the snackbar should disappear.</param>
void Show(
string title,
string message,
IconElement icon,
TimeSpan timeout
);
/// <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">Name displayed on top of snackbar.</param>
/// <param name="message">Message inside the snackbar.</param>
/// <param name="appearance">Display style.</param>
/// <param name="icon">Additional icon on the left.</param>
/// <param name="timeout">The time after which the snackbar should disappear.</param>
void Show(
string title,
string message,
ControlAppearance appearance = ControlAppearance.Secondary,
IconElement? icon = null,
TimeSpan timeout = default
ControlAppearance appearance,
IconElement? icon,
TimeSpan timeout
);
}
......@@ -4,7 +4,6 @@
// All Rights Reserved.
using System;
using Wpf.Ui.Contracts;
using Wpf.Ui.Controls;
namespace Wpf.Ui;
......@@ -15,6 +14,7 @@ namespace Wpf.Ui;
public class SnackbarService : ISnackbarService
{
private SnackbarPresenter? _presenter;
private Snackbar? _snackbar;
/// <inheritdoc />
......@@ -30,31 +30,72 @@ public void SetSnackbarPresenter(SnackbarPresenter contentPresenter)
public SnackbarPresenter GetSnackbarPresenter()
{
if (_presenter is null)
{
throw new ArgumentNullException($"The SnackbarPresenter didn't set previously.");
}
return _presenter;
}
/// <inheritdoc />
public void Show(string title, string message)
{
Show(title, message, ControlAppearance.Secondary, null, new TimeSpan(2));
}
/// <inheritdoc />
public void Show(string title, string message, ControlAppearance appearance)
{
Show(title, message, appearance, null, new TimeSpan(2));
}
/// <inheritdoc />
public void Show(string title, string message, IconElement icon)
{
Show(title, message, ControlAppearance.Secondary, icon, new TimeSpan(2));
}
/// <inheritdoc />
public void Show(string title, string message, TimeSpan timeout)
{
Show(title, message, ControlAppearance.Secondary, null, timeout);
}
/// <inheritdoc />
public void Show(string title, string message, ControlAppearance appearance, TimeSpan timeout)
{
Show(title, message, appearance, null, timeout);
}
/// <inheritdoc />
public void Show(string title, string message, IconElement icon, TimeSpan timeout)
{
Show(title, message, ControlAppearance.Secondary, icon, timeout);
}
/// <inheritdoc />
public void Show(
string title,
string message,
ControlAppearance appearance = ControlAppearance.Secondary,
IconElement? icon = null,
TimeSpan timeout = default
ControlAppearance appearance,
IconElement? icon,
TimeSpan timeout
)
{
if (_presenter is null)
{
throw new ArgumentNullException($"The SnackbarPresenter didn't set previously.");
}
_snackbar ??= new Snackbar(_presenter);
_snackbar.Title = title;
_snackbar.Content = message;
_snackbar.Appearance = appearance;
_snackbar.Icon = icon;
_snackbar.Timeout = timeout.TotalSeconds == 0 ? DefaultTimeOut : timeout;
_snackbar.SetCurrentValue(Snackbar.TitleProperty, title);
_snackbar.SetCurrentValue(System.Windows.Controls.ContentControl.ContentProperty, message);
_snackbar.SetCurrentValue(Snackbar.AppearanceProperty, appearance);
_snackbar.SetCurrentValue(Snackbar.IconProperty, icon);
_snackbar.SetCurrentValue(Snackbar.TimeoutProperty, timeout.TotalSeconds == 0 ? DefaultTimeOut : timeout);
_snackbar.Show(true);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册