添加项目文件。
This commit is contained in:
1 parent
54c7b83029
commit
ef50fa0620
84 files changed
+9188
No files matched your search
@@ -0,0 +1,137 @@
|
||||
|
||||
using MAX.Framework.Controls;
|
||||
using MAX.Framework.Controls.Attach;
|
||||
using Prism.Services.Dialogs;
|
||||
using Store.Management.Framework.Controls;
|
||||
using Store.Management.Framework.Controls.Attach;
|
||||
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.Shapes;
|
||||
using MAX.Framework.Extensions;
|
||||
|
||||
namespace Store.Management.Framework.Controls;
|
||||
|
||||
/// <summary>
|
||||
/// DialogWindow.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class DialogWindow : WindowBase, IDialogWindow
|
||||
{
|
||||
private readonly Style dialogWindowStyle;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="IDialogResult"/> of the dialog.
|
||||
/// </summary>
|
||||
public IDialogResult Result { get; set; }
|
||||
private bool isConstructorSuccessful = false;
|
||||
public DialogWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
Owner = Application.Current.MainWindow;
|
||||
isConstructorSuccessful = true;
|
||||
dialogWindowStyle = (Style)TryFindResource("DialogWindowStyle");
|
||||
|
||||
{
|
||||
RoutedCommand escapeCommand = new RoutedCommand();
|
||||
CommandBindings.Add(new CommandBinding(escapeCommand, new ExecutedRoutedEventHandler((s, e) =>
|
||||
{
|
||||
if (DataContext is ConfirmDialogViewModel vm && vm.AllowEscape)
|
||||
{
|
||||
vm.CancelCommand?.Execute(null);
|
||||
}
|
||||
})));
|
||||
InputBindings.Add(new InputBinding(escapeCommand, new KeyGesture(Key.Escape)));
|
||||
}
|
||||
|
||||
{
|
||||
RoutedCommand enterCommand = new RoutedCommand();
|
||||
CommandBindings.Add(new CommandBinding(enterCommand, new ExecutedRoutedEventHandler((s, e) =>
|
||||
{
|
||||
if (DataContext is ConfirmDialogViewModel vm && vm.AllowEnter)
|
||||
{
|
||||
vm.ConfirmCommand?.Execute(null);
|
||||
}
|
||||
})));
|
||||
InputBindings.Add(new InputBinding(enterCommand, new KeyGesture(Key.Enter)));
|
||||
}
|
||||
|
||||
Loaded += DialogWindow_Loaded;
|
||||
}
|
||||
|
||||
private void DialogWindow_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Loaded -= DialogWindow_Loaded;
|
||||
if (DataContext is ConfirmDialogViewModel viewModel)
|
||||
{
|
||||
viewModel.Loaded(Content);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnContentChanged(object oldContent, object newContent)
|
||||
{
|
||||
this.Style = dialogWindowStyle;
|
||||
if (newContent is UserControl control)
|
||||
{
|
||||
|
||||
Setter widthSetter = this.Style.Setters.OfType<Setter>().FirstOrDefault(a => a.Property == WidthProperty);
|
||||
if (widthSetter == null)
|
||||
{
|
||||
if (double.IsNaN(control.Width))
|
||||
{
|
||||
this.Width = DialogWindowProperty.GetWidth(control);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Width = control.Width;
|
||||
control.Width = double.NaN;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Setter heightSetter = this.Style.Setters.OfType<Setter>().FirstOrDefault(a => a.Property == HeightProperty);
|
||||
if (heightSetter == null)
|
||||
{
|
||||
if (double.IsNaN(control.Height))
|
||||
{
|
||||
this.Height = DialogWindowProperty.GetHeight(control);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Height = control.Height;
|
||||
control.Height = double.NaN;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ResizeMode resizeExt = DialogWindowProperty.GetResizeMode(control);
|
||||
if (resizeExt != ResizeMode.CanResize)
|
||||
{
|
||||
this.ResizeMode = resizeExt;
|
||||
}
|
||||
|
||||
}
|
||||
base.OnContentChanged(oldContent, newContent);
|
||||
}
|
||||
|
||||
protected override void OnStyleChanged(Style oldStyle, Style newStyle)
|
||||
{
|
||||
if (newStyle.TargetType == typeof(Window))
|
||||
{
|
||||
if (isConstructorSuccessful)
|
||||
{
|
||||
dialogWindowStyle.Merge(newStyle);
|
||||
}
|
||||
return;
|
||||
}
|
||||
base.OnStyleChanged(oldStyle, newStyle);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user