一、目的:不同交互場景需要提示不同的消息,不同的消息需要用不同的效果來展示,應用DialogHost(對話框)、NotifyIcon(消息提示)、Snackbar(氣泡消息)顯示各種場景提示消息,應用在ViewModel中
二、實現:
1、等待對話框
2、確定對話框
3、確定與取消對話框
4、百分比進度和文本進度對話框
5、氣泡提示消息(NotifyIcon)
6、提示消息(Snackbar)
三、示例:
說明:
1、對話框:常規對話消息如上圖,等待對話框、消息對話、進度對話框;
(目前只封裝如上這幾種,自定義對話框只需創建用戶控件調用通用加載方法即可,後續更新...)
2、提示消息:當進度保存成功是需要一個提示消息,顯示2s自動隱藏即可(如圖中友情提示部分分) ;
3、氣泡消息:當程序處於隱藏或某種狀態時需要應用氣泡提示消息;
四、代碼:
[ViewModel("Loyout")]
class LoyoutViewModel : MvcViewModelBase
{
/// <summary> 命令通用方法 </summary>
protected override async void RelayMethod(object obj)
{
string command = obj?.ToString();
// Do:對話消息
if (command == "Button.ShowDialogMessage")
{
await MessageService.ShowSumitMessge("這是消息對話框?");
}
// Do:等待消息
else if (command == "Button.ShowWaittingMessge")
{
await MessageService.ShowWaittingMessge(() => Thread.Sleep(2000));
}
// Do:百分比進度對話框
else if (command == "Button.ShowPercentProgress")
{
Action<IPercentProgress> action = l =>
{
for (int i = 0; i < 100; i++)
{
l.Value = i;
Thread.Sleep(50);
}
Thread.Sleep(1000);
MessageService.ShowSnackMessageWithNotice("加載完成!");
};
await MessageService.ShowPercentProgress(action);
}
// Do:文本進度對話框
else if (command == "Button.ShowStringProgress")
{
Action<IStringProgress> action = l =>
{
for (int i = 1; i <= 100; i++)
{
l.MessageStr = $"正在提交當前頁第{i}份數據,共100份";
Thread.Sleep(50);
}
Thread.Sleep(1000);
MessageService.ShowSnackMessageWithNotice("提交完成:成功100條,失敗0條!");
};
await MessageService.ShowStringProgress(action);
}
// Do:確認取消對話框
else if (command == "Button.ShowResultMessge")
{
Action<object, DialogClosingEventArgs> action = (l, k) =>
{
if ((bool)k.Parameter)
{
MessageService.ShowSnackMessageWithNotice("你點擊了取消");
}
else
{
MessageService.ShowSnackMessageWithNotice("你點擊了確定");
}
};
MessageService.ShowResultMessge("確認要退出系統?", action);
}
// Do:提示消息
else if (command == "Button.ShowSnackMessage")
{
MessageService.ShowSnackMessageWithNotice("這是提示消息?");
}
// Do:氣泡消息
else if (command == "Button.ShowNotifyMessage")
{
MessageService.ShowNotifyMessage("你有一條報警信息需要處理,請檢查", "Notify By HeBianGu");
}
}
}