完成AlertDialog

croire 3 years ago
parent 588599e1cf
commit 76c968ac39

@ -194,6 +194,7 @@ namespace DownKyi
containerRegistry.RegisterForNavigation<Views.UserSpace.ViewChannel>(ViewModels.UserSpace.ViewChannelViewModel.Tag);
// dialogs
containerRegistry.RegisterDialog<ViewAlertDialog>(ViewAlertDialogViewModel.Tag);
containerRegistry.RegisterDialog<ViewDownloadSetter>(ViewDownloadSetterViewModel.Tag);
containerRegistry.RegisterDialog<ViewParsingSelector>(ViewParsingSelectorViewModel.Tag);

@ -115,10 +115,12 @@
<Compile Include="Models\Downloading.cs" />
<Compile Include="Models\DownloadStatus.cs" />
<Compile Include="Models\OrderFormatDisplay.cs" />
<Compile Include="Services\AlertService.cs" />
<Compile Include="Services\Download\AddToDownloadService.cs" />
<Compile Include="Services\Download\DownloadStorageService.cs" />
<Compile Include="Services\SearchService.cs" />
<Compile Include="Utils\WindowAdaptation.cs" />
<Compile Include="ViewModels\Dialogs\ViewAlertDialogViewModel.cs" />
<Compile Include="ViewModels\PageViewModels\BangumiFollowMedia.cs" />
<Compile Include="ViewModels\PageViewModels\Favorites.cs" />
<Compile Include="ViewModels\PageViewModels\FavoritesMedia.cs" />
@ -186,6 +188,9 @@
<Compile Include="ViewModels\ViewUserSpaceViewModel.cs" />
<Compile Include="ViewModels\ViewVideoDetailViewModel.cs" />
<Compile Include="ViewModels\Settings\ViewVideoViewModel.cs" />
<Compile Include="Views\Dialogs\ViewAlertDialog.xaml.cs">
<DependentUpon>ViewAlertDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Dialogs\ViewDownloadSetter.xaml.cs">
<DependentUpon>ViewDownloadSetter.xaml</DependentUpon>
</Compile>
@ -344,6 +349,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Dialogs\ViewAlertDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Dialogs\ViewDownloadSetter.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

@ -65,6 +65,34 @@
l1.8-2.2c0-0.1,0-0.5-0.1-0.8l-3.1-3.6C29.7,17.1,29.5,17,29.2,17z",
Fill = "#FF000000"
};
Info = new VectorImage
{
Height = 20,
Width = 20,
Data = @"M11 7h2v2h-2zm0 4h2v6h-2zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0
18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z",
Fill = "#FF00bcf2"
};
Warning = new VectorImage
{
Height = 20,
Width = 20,
Data = @"M12 5.99L19.53 19H4.47L12 5.99M2.74 18c-.77 1.33.19 3 1.73 3h15.06c1.54 0 2.5-1.67 1.73-3L13.73
4.99c-.77-1.33-2.69-1.33-3.46 0L2.74 18zM11 11v2c0 .55.45 1 1 1s1-.45 1-1v-2c0-.55-.45-1-1-1s-1 .45-1 1zm0 5h2v2h-2z",
Fill = "#FFffb900"
};
Error = new VectorImage
{
Height = 20,
Width = 20,
Data = @"M12 7c.55 0 1 .45 1 1v4c0 .55-.45 1-1 1s-1-.45-1-1V8c0-.55.45-1 1-1zm-.01-5C6.47 2 2 6.48 2 12s4.47
10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8
8-3.58 8-8 8zm1-3h-2v-2h2v2z",
Fill = "#FFd83b01"
};
}
public VectorImage Close { get; private set; }
@ -72,5 +100,9 @@
public VectorImage Minimize { get; private set; }
public VectorImage Restore { get; private set; }
public VectorImage Skin { get; private set; }
public VectorImage Info { get; private set; }
public VectorImage Warning { get; private set; }
public VectorImage Error { get; private set; }
}
}

@ -293,6 +293,11 @@
<system:String x:Key="ExtractVideo">提取视频</system:String>
<!-- Dialog -->
<system:String x:Key="Info">信息</system:String>
<system:String x:Key="Warning">警告</system:String>
<system:String x:Key="Error">错误</system:String>
<system:String x:Key="Allow">确定</system:String>
<system:String x:Key="Cancel">取消</system:String>
<system:String x:Key="SelectDirectory">请选择文件夹</system:String>

@ -0,0 +1,71 @@
using DownKyi.Images;
using DownKyi.Utils;
using DownKyi.ViewModels.Dialogs;
using Prism.Services.Dialogs;
namespace DownKyi.Services
{
public class AlertService
{
private readonly IDialogService dialogService;
public AlertService(IDialogService dialogService)
{
this.dialogService = dialogService;
}
/// <summary>
/// 显示一个信息弹窗
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public ButtonResult ShowInfo(string message)
{
VectorImage image = SystemIcon.Instance().Info;
string title = DictionaryResource.GetString("Info");
return ShowMessage(image, title, message);
}
/// <summary>
/// 显示一个警告弹窗
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public ButtonResult ShowWarning(string message)
{
VectorImage image = SystemIcon.Instance().Warning;
string title = DictionaryResource.GetString("Warning");
return ShowMessage(image, title, message);
}
/// <summary>
/// 显示一个错误弹窗
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public ButtonResult ShowError(string message)
{
VectorImage image = SystemIcon.Instance().Error;
string title = DictionaryResource.GetString("Error");
return ShowMessage(image, title, message);
}
private ButtonResult ShowMessage(VectorImage image, string type, string message)
{
ButtonResult result = ButtonResult.None;
DialogParameters param = new DialogParameters
{
{ "image", image },
{ "title", type },
{ "message", message }
};
dialogService.ShowDialog(ViewAlertDialogViewModel.Tag, param, buttonResult =>
{
result = buttonResult.Result;
});
return result;
}
}
}

@ -1,6 +1,7 @@
using Prism.Events;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Windows;
@ -9,6 +10,7 @@ namespace DownKyi.ViewModels
public class BaseViewModel : BindableBase, INavigationAware
{
protected readonly IEventAggregator eventAggregator;
protected readonly IDialogService dialogService;
protected string ParentView = string.Empty;
public BaseViewModel(IEventAggregator eventAggregator)
@ -16,6 +18,12 @@ namespace DownKyi.ViewModels
this.eventAggregator = eventAggregator;
}
public BaseViewModel(IEventAggregator eventAggregator, IDialogService dialogService)
{
this.eventAggregator = eventAggregator;
this.dialogService = dialogService;
}
public bool IsNavigationTarget(NavigationContext navigationContext)
{
return true;

@ -115,16 +115,16 @@ namespace DownKyi.ViewModels.Dialogs
public event Action<IDialogResult> RequestClose;
public bool CanCloseDialog()
public virtual bool CanCloseDialog()
{
return true;
}
public void OnDialogClosed()
public virtual void OnDialogClosed()
{
}
public void OnDialogOpened(IDialogParameters parameters)
public virtual void OnDialogOpened(IDialogParameters parameters)
{
}

@ -0,0 +1,65 @@
using DownKyi.Images;
using Prism.Commands;
using Prism.Services.Dialogs;
namespace DownKyi.ViewModels.Dialogs
{
public class ViewAlertDialogViewModel : BaseDialogViewModel
{
public const string Tag = "DialogAlert";
#region 页面属性申明
private VectorImage image;
public VectorImage Image
{
get => image;
set => SetProperty(ref image, value);
}
private string message;
public string Message
{
get { return message; }
set { SetProperty(ref message, value); }
}
#endregion
public ViewAlertDialogViewModel()
{
}
#region 命令申明
// 确认事件
private DelegateCommand allowCommand;
public DelegateCommand AllowCommand => allowCommand ?? (allowCommand = new DelegateCommand(ExecuteAllowCommand));
/// <summary>
/// 确认事件
/// </summary>
private void ExecuteAllowCommand()
{
ButtonResult result = ButtonResult.OK;
RaiseRequestClose(new DialogResult(result));
}
#endregion
#region 接口实现
public override void OnDialogOpened(IDialogParameters parameters)
{
base.OnDialogOpened(parameters);
Image = parameters.GetValue<VectorImage>("image");
Title = parameters.GetValue<string>("title");
Message = parameters.GetValue<string>("message");
}
#endregion
}
}

@ -9,6 +9,7 @@ using DownKyi.Utils;
using Prism.Commands;
using Prism.Events;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.IO;
using System.Threading.Tasks;
@ -88,7 +89,7 @@ namespace DownKyi.ViewModels
#endregion
public ViewIndexViewModel(IEventAggregator eventAggregator) : base(eventAggregator)
public ViewIndexViewModel(IEventAggregator eventAggregator, IDialogService dialogService) : base(eventAggregator, dialogService)
{
#region 属性初始化
@ -207,7 +208,10 @@ namespace DownKyi.ViewModels
/// </summary>
private void EnterBili()
{
if (InputText == null || InputText == string.Empty) { return; }
if (InputText == null || InputText == string.Empty)
{
return;
}
LogManager.Debug(Tag, $"InputText: {InputText}");

@ -27,8 +27,6 @@ namespace DownKyi.ViewModels
{
public const string Tag = "PageVideoDetail";
private readonly IDialogService dialogService;
// 保存输入字符串,避免被用户修改
private string input = null;
@ -106,10 +104,8 @@ namespace DownKyi.ViewModels
#endregion
public ViewVideoDetailViewModel(IEventAggregator eventAggregator, IDialogService dialogService) : base(eventAggregator)
public ViewVideoDetailViewModel(IEventAggregator eventAggregator, IDialogService dialogService) : base(eventAggregator, dialogService)
{
this.dialogService = dialogService;
#region 属性初始化
// 初始化loading gif

@ -0,0 +1,144 @@
<UserControl
x:Class="DownKyi.Views.Dialogs.ViewAlertDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True">
<prism:Dialog.WindowStyle>
<Style TargetType="Window">
<Setter Property="prism:Dialog.WindowStartupLocation" Value="CenterOwner" />
<Setter Property="ResizeMode" Value="NoResize" />
<Setter Property="ShowInTaskbar" Value="False" />
<Setter Property="SizeToContent" Value="WidthAndHeight" />
<Setter Property="WindowStyle" Value="None" />
</Style>
</prism:Dialog.WindowStyle>
<Border BorderBrush="{DynamicResource BrushWindowBorder}" BorderThickness="1,1,0.6,0.6">
<Grid Background="{DynamicResource BrushBackground}">
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid
Grid.Row="0"
Background="{DynamicResource BrushBackgroundGreyTranslucent3}"
KeyboardNavigation.TabNavigation="None">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="50" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="50" />
</Grid.ColumnDefinitions>
<StackPanel
Grid.Column="0"
Margin="10,0"
VerticalAlignment="Center"
Orientation="Horizontal">
<ContentControl Margin="0,0,10,0">
<Path
Width="{Binding Image.Width}"
Height="{Binding Image.Height}"
Data="{Binding Image.Data}"
Fill="{Binding Image.Fill}"
Stretch="Uniform" />
<ContentControl.Style>
<Style TargetType="{x:Type ContentControl}">
<Setter Property="Visibility" Value="Visible" />
<Style.Triggers>
<DataTrigger Binding="{Binding Image}" Value="{x:Null}">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</ContentControl.Style>
</ContentControl>
<TextBlock
VerticalAlignment="Center"
FontSize="14"
Foreground="{DynamicResource BrushCaptionForeground}"
Text="{Binding Title}" />
</StackPanel>
<Button
Grid.Column="4"
Command="{Binding CloseCommand}"
Style="{StaticResource CloseBtnStyle}"
ToolTip="{DynamicResource Close}">
<Path
Width="{Binding CloseIcon.Width}"
Height="{Binding CloseIcon.Height}"
Data="{Binding CloseIcon.Data}"
Fill="{Binding CloseIcon.Fill}"
Stretch="UniformToFill" />
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseEnter">
<i:InvokeCommandAction Command="{Binding CloseEnterCommand}" />
</i:EventTrigger>
<i:EventTrigger EventName="MouseLeave">
<i:InvokeCommandAction Command="{Binding CloseLeaveCommand}" />
</i:EventTrigger>
<i:EventTrigger EventName="LostMouseCapture">
<i:InvokeCommandAction Command="{Binding CloseLeaveCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</Grid>
<Grid Grid.Row="1" Margin="15,10,15,20">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0"
MaxWidth="500"
MaxHeight="180"
Margin="0,10,0,30"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="14"
Foreground="{DynamicResource BrushTextDark}"
Text="{Binding Message}"
TextTrimming="CharacterEllipsis"
TextWrapping="WrapWithOverflow" />
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="100" />
<ColumnDefinition MinWidth="100" />
</Grid.ColumnDefinitions>
<Button
Grid.Column="0"
Width="75"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
Command="{Binding AllowCommand}"
Content="{DynamicResource Allow}"
FontSize="12"
Foreground="{DynamicResource BrushText}"
Style="{StaticResource BtnStyle}" />
<Button
Grid.Column="1"
Width="75"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
Command="{Binding CloseCommand}"
Content="{DynamicResource Cancel}"
FontSize="12"
Foreground="{DynamicResource BrushText}"
Style="{StaticResource BtnStyle}" />
</Grid>
</Grid>
</Grid>
</Border>
</UserControl>

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace DownKyi.Views.Dialogs
{
/// <summary>
/// ViewAlertDialog.xaml 的交互逻辑
/// </summary>
public partial class ViewAlertDialog : UserControl
{
public ViewAlertDialog()
{
InitializeComponent();
}
}
}

@ -24,7 +24,7 @@
<Grid
Grid.Row="0"
Background="{DynamicResource BrushCaptionBackground}"
Background="{DynamicResource BrushBackgroundGreyTranslucent3}"
KeyboardNavigation.TabNavigation="None">
<!--<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
@ -65,6 +65,9 @@
<i:EventTrigger EventName="MouseLeave">
<i:InvokeCommandAction Command="{Binding CloseLeaveCommand}" />
</i:EventTrigger>
<i:EventTrigger EventName="LostMouseCapture">
<i:InvokeCommandAction Command="{Binding CloseLeaveCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</Grid>

@ -24,7 +24,7 @@
<Grid
Grid.Row="0"
Background="{DynamicResource BrushCaptionBackground}"
Background="{DynamicResource BrushBackgroundGreyTranslucent3}"
KeyboardNavigation.TabNavigation="None">
<!--<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
@ -65,6 +65,9 @@
<i:EventTrigger EventName="MouseLeave">
<i:InvokeCommandAction Command="{Binding CloseLeaveCommand}" />
</i:EventTrigger>
<i:EventTrigger EventName="LostMouseCapture">
<i:InvokeCommandAction Command="{Binding CloseLeaveCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</Grid>

Loading…
Cancel
Save