From f772c35ede187b41190de5278c73dccefa73800d Mon Sep 17 00:00:00 2001 From: chfei Date: Wed, 2 Sep 2026 13:45:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Ctrls/Statistics/ShowOrderDialogView.xaml | 19 +- Main.Test/App.xaml | 13 +- Main.Test/DataGridHelper.cs | 58 ++ Main.Test/Dictionary1.xaml | 436 ++++++++++ Main.Test/Dictionary2.xaml | 428 ++++++++++ Main.Test/Main.Test.csproj | 4 + Main.Test/MainHeaderImageContent.xaml | 13 + Main.Test/MainHeaderImageContent.xaml.cs | 57 ++ Main.Test/MainWindow.xaml | 50 +- Main.Test/MainWindow.xaml.cs | 17 +- Main.Test/ViewModels/HeaderViewModel.cs | 2 +- Main.Test/ViewModels/MainViewModel.cs | 20 +- .../Controls/Attach/DialogWindowProperty.cs | 47 ++ .../MAX.Framework/Controls/ConfirmDialog.cs | 290 +++++++ .../Extensions/StyleExtensions.cs | 93 +++ Source/Trade.Framework/AssemblyInfo.cs | 4 +- .../Controls/Attach/DataGridHelper.cs | 58 ++ .../Controls/DialogWindow.xaml | 12 + .../Controls/DialogWindow.xaml.cs | 134 ++++ Source/Trade.Framework/Controls/WindowBase.cs | 9 +- .../Trade.Framework/FrameworkApplication.cs | 2 + Source/Trade.Framework/Resources/Theme.xaml | 433 ++++++++++ Source/Trade.Framework/Trade.Framework.csproj | 8 +- WxOrder.Framework/AssemblyInfo.cs | 8 + .../Controls/Attach/DataGridHelper.cs | 58 ++ WxOrder.Framework/Resources/Theme.xaml | 751 ++++++++---------- WxOrder.Framework/WxOrder.Framework.csproj | 1 - 27 files changed, 2585 insertions(+), 440 deletions(-) create mode 100644 Main.Test/DataGridHelper.cs create mode 100644 Main.Test/Dictionary1.xaml create mode 100644 Main.Test/Dictionary2.xaml create mode 100644 Main.Test/MainHeaderImageContent.xaml create mode 100644 Main.Test/MainHeaderImageContent.xaml.cs create mode 100644 Source/MAX.Framework/Controls/Attach/DialogWindowProperty.cs create mode 100644 Source/MAX.Framework/Controls/ConfirmDialog.cs create mode 100644 Source/MAX.Framework/Extensions/StyleExtensions.cs create mode 100644 Source/Trade.Framework/Controls/Attach/DataGridHelper.cs create mode 100644 Source/Trade.Framework/Controls/DialogWindow.xaml create mode 100644 Source/Trade.Framework/Controls/DialogWindow.xaml.cs create mode 100644 Source/Trade.Framework/Resources/Theme.xaml create mode 100644 WxOrder.Framework/AssemblyInfo.cs create mode 100644 WxOrder.Framework/Controls/Attach/DataGridHelper.cs diff --git a/29WxOrderWpf/Ctrls/Statistics/ShowOrderDialogView.xaml b/29WxOrderWpf/Ctrls/Statistics/ShowOrderDialogView.xaml index 6eb7118..c15d798 100644 --- a/29WxOrderWpf/Ctrls/Statistics/ShowOrderDialogView.xaml +++ b/29WxOrderWpf/Ctrls/Statistics/ShowOrderDialogView.xaml @@ -20,26 +20,13 @@ - + Style="{StaticResource DefaultDataGridStyle}" + VerticalScrollBarVisibility="Visible"> - + + + + + + + + + + + + \ No newline at end of file diff --git a/Main.Test/DataGridHelper.cs b/Main.Test/DataGridHelper.cs new file mode 100644 index 0000000..2cab66c --- /dev/null +++ b/Main.Test/DataGridHelper.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace Main.Test; + +public class DataGridHelper +{ + /// + /// + /// + /// + /// + public static string GetNoDataTips(DependencyObject obj) + { + return (string)obj.GetValue(NoDataTipsProperty); + } + + /// + /// + /// + /// + /// + public static void SetNoDataTips(DependencyObject obj, string value) + { + obj.SetValue(NoDataTipsProperty, value); + } + + public static readonly DependencyProperty NoDataTipsProperty = + DependencyProperty.RegisterAttached("NoDataTips", typeof(string), typeof(DataGridHelper),new PropertyMetadata("无数据")); + + /// + /// + /// + /// + /// + public static bool GetIsActive(DependencyObject obj) + { + return (bool)obj.GetValue(IsActiveProperty); + } + + /// + /// + /// + /// + /// + public static void SetIsActive(DependencyObject obj, bool value) + { + obj.SetValue(IsActiveProperty, value); + } + + public static readonly DependencyProperty IsActiveProperty = + DependencyProperty.RegisterAttached("IsActive", typeof(bool), typeof(DataGridHelper)); + +} diff --git a/Main.Test/Dictionary1.xaml b/Main.Test/Dictionary1.xaml new file mode 100644 index 0000000..690384f --- /dev/null +++ b/Main.Test/Dictionary1.xaml @@ -0,0 +1,436 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Main.Test/Dictionary2.xaml b/Main.Test/Dictionary2.xaml new file mode 100644 index 0000000..7398e4e --- /dev/null +++ b/Main.Test/Dictionary2.xaml @@ -0,0 +1,428 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Main.Test/Main.Test.csproj b/Main.Test/Main.Test.csproj index a6124fb..0af437b 100644 --- a/Main.Test/Main.Test.csproj +++ b/Main.Test/Main.Test.csproj @@ -8,6 +8,10 @@ true + + + + diff --git a/Main.Test/MainHeaderImageContent.xaml b/Main.Test/MainHeaderImageContent.xaml new file mode 100644 index 0000000..b56c5c7 --- /dev/null +++ b/Main.Test/MainHeaderImageContent.xaml @@ -0,0 +1,13 @@ + + + diff --git a/Main.Test/MainHeaderImageContent.xaml.cs b/Main.Test/MainHeaderImageContent.xaml.cs new file mode 100644 index 0000000..59629c2 --- /dev/null +++ b/Main.Test/MainHeaderImageContent.xaml.cs @@ -0,0 +1,57 @@ +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 Main.Test +{ + /// + /// MainHeaderImageContent.xaml 的交互逻辑 + /// + public partial class MainHeaderImageContent : UserControl + { + public MainHeaderImageContent() + { + InitializeComponent(); + } + private void IndicatorItem_PreviewMouseDown(object sender, MouseButtonEventArgs e) + { + e.Handled = true; + TryDragMove(); + } + + private void TimeItem_PreviewMouseDown(object sender, MouseButtonEventArgs e) + { + e.Handled = true; + TryDragMove(); + } + + private void TryDragMove() + { + Window window = Application.Current?.MainWindow; + if (window is null) + { + return; + } + try + { + //if (window.WindowState == WindowState.Maximized) + //{ + // window.WindowState = WindowState.Normal; + //} + window.DragMove(); + } + catch { } + } + } +} diff --git a/Main.Test/MainWindow.xaml b/Main.Test/MainWindow.xaml index 54af584..cdb697d 100644 --- a/Main.Test/MainWindow.xaml +++ b/Main.Test/MainWindow.xaml @@ -1,19 +1,57 @@ - - - + + + + + + + + + + - + diff --git a/Main.Test/MainWindow.xaml.cs b/Main.Test/MainWindow.xaml.cs index 7e781b9..9a54dcc 100644 --- a/Main.Test/MainWindow.xaml.cs +++ b/Main.Test/MainWindow.xaml.cs @@ -1,4 +1,5 @@ -using System.Text; +using Bogus; +using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; @@ -8,15 +9,27 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using Trade.Framework.Controls; namespace Main.Test; /// /// Interaction logic for MainWindow.xaml /// -public partial class MainWindow : Window +public partial class MainWindow : WindowBase { public MainWindow() { InitializeComponent(); + var mainHeaderImageContent = new MainHeaderImageContent(); + NonClientAreaHeight = mainHeaderImageContent.Height; + NonClientAreaContent = mainHeaderImageContent; } +} + +public class ItemInfo +{ + public int Code { get; set; } + public string Name { get; set; } + public string Value { get; set; } + public int Qty { get; set; } } \ No newline at end of file diff --git a/Main.Test/ViewModels/HeaderViewModel.cs b/Main.Test/ViewModels/HeaderViewModel.cs index 5e66fd0..beb798d 100644 --- a/Main.Test/ViewModels/HeaderViewModel.cs +++ b/Main.Test/ViewModels/HeaderViewModel.cs @@ -11,7 +11,7 @@ using System.Windows.Input; namespace Main.Test.ViewModels; -internal class HeaderViewModel +internal partial class HeaderViewModel { private readonly IDialogService _dialogService; diff --git a/Main.Test/ViewModels/MainViewModel.cs b/Main.Test/ViewModels/MainViewModel.cs index eacab68..820ad91 100644 --- a/Main.Test/ViewModels/MainViewModel.cs +++ b/Main.Test/ViewModels/MainViewModel.cs @@ -1,4 +1,5 @@ -using MAX.Core.Logger; +using Bogus; +using MAX.Core.Logger; using System; using System.Collections.Generic; using System.Linq; @@ -11,10 +12,27 @@ namespace Main.Test.ViewModels; internal class MainViewModel { private readonly ILoggerFacade _logger; + public List Data { get; set; } public MainViewModel(ILoggerFacade logger, UserManager userManager) { _logger = logger; _logger.Info("123123"); + + + + // 创建 Faker 并配置规则 + var itemFaker = new Faker() + .RuleFor(x => x.Code, f => f.Random.Int(1000, 9999)) // 4位随机编码 + .RuleFor(x => x.Name, f => f.Commerce.ProductName()) // 商品名称 + .RuleFor(x => x.Value, f => f.Commerce.Price().ToString()) // 商品价格 + .RuleFor(x => x.Qty, f => f.Random.Int(1, 100)); // 1-100的随机数量 + + // 生成单个对象 + var singleItem = itemFaker.Generate(); + + // 生成100个对象 + Data = itemFaker.Generate(100); + //Data.Clear(); } } diff --git a/Source/MAX.Framework/Controls/Attach/DialogWindowProperty.cs b/Source/MAX.Framework/Controls/Attach/DialogWindowProperty.cs new file mode 100644 index 0000000..de2308b --- /dev/null +++ b/Source/MAX.Framework/Controls/Attach/DialogWindowProperty.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace MAX.Framework.Controls.Attach; + +/// +/// 弹出窗口属性值 +/// +public class DialogWindowProperty +{ + public static readonly DependencyProperty WindowStartupLocationProperty = DependencyProperty.RegisterAttached( + "WindowStartupLocation", typeof(WindowStartupLocation), typeof(DialogWindowProperty), new PropertyMetadata(WindowStartupLocation.CenterScreen)); + public static void SetWindowStartupLocation(DependencyObject element, WindowStartupLocation value) + => element.SetValue(WindowStartupLocationProperty, value); + public static WindowStartupLocation GetWindowStartupLocation(DependencyObject element) + => (WindowStartupLocation)element.GetValue(WindowStartupLocationProperty); + + + public static readonly DependencyProperty ResizeModeProperty = DependencyProperty.RegisterAttached( + "ResizeMode", typeof(ResizeMode), typeof(DialogWindowProperty), new PropertyMetadata(ResizeMode.CanResize)); + public static void SetResizeMode(DependencyObject element, ResizeMode value) + => element.SetValue(ResizeModeProperty, value); + public static ResizeMode GetResizeMode(DependencyObject element) + => (ResizeMode)element.GetValue(ResizeModeProperty); + + + + public static readonly DependencyProperty WidthProperty = DependencyProperty.RegisterAttached( + "Width", typeof(double), typeof(DialogWindowProperty), new PropertyMetadata(double.NaN)); + public static void SetWidth(DependencyObject element, double value) + => element.SetValue(WidthProperty, value); + public static double GetWidth(DependencyObject element) + => (double)element.GetValue(WidthProperty); + + + + public static readonly DependencyProperty HeightProperty = DependencyProperty.RegisterAttached( + "Height", typeof(double), typeof(DialogWindowProperty), new PropertyMetadata(double.NaN)); + public static void SetHeight(DependencyObject element, double value) + => element.SetValue(HeightProperty, value); + public static double GetHeight(DependencyObject element) + => (double)element.GetValue(HeightProperty); +} diff --git a/Source/MAX.Framework/Controls/ConfirmDialog.cs b/Source/MAX.Framework/Controls/ConfirmDialog.cs new file mode 100644 index 0000000..610d819 --- /dev/null +++ b/Source/MAX.Framework/Controls/ConfirmDialog.cs @@ -0,0 +1,290 @@ +using MAX.Core.Commons; +using Prism.Commands; +using Prism.Mvvm; +using Prism.Services.Dialogs; +using System; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Input; +using System.Windows.Media; + +namespace MAX.Framework.Controls; + +public static class IDialogServiceExtension +{ + public static void ShowDialog(this IDialogService dialogService, string name, TParameter parameter, Action callback) where TParameter : class + { + dialogService.ShowDialog(name, new DialogParameters + { + {"parameter", parameter}, + }, callback); + } + public static void Show(this IDialogService dialogService, string name, TParameter parameter, Action callback) where TParameter : class + { + dialogService.Show(name, new DialogParameters + { + {"parameter", parameter}, + }, callback); + } +} + + +/// +/// 确定取消对话框 ViewModel +/// +public class ConfirmDialogViewModel : BindableBase, IDialogAware +{ + public ConfirmDialogViewModel() + { + + } + + private string title = ""; + private bool _enableConfirm = true; + private bool _ShowConfirm = true; + private bool _ShowCancel = true; + private bool _ShowErrorMsg = true; + private string _ErrorMsg = ""; + private string confirmText = "确定"; + private string cancelText = "取消"; + private string backText = "返回"; + private bool allowEscape = true; + private bool allowEnter = true; + private bool isLoading = false; + + public string Title + { + get => title; + protected set => SetProperty(ref title, value); + } + + public bool AllowEscape + { + get => allowEscape; + set => SetProperty(ref allowEscape, value); + } + + public bool AllowEnter + { + get => allowEnter; + set => SetProperty(ref allowEnter, value); + } + + public bool IsLoading + { + get => isLoading; + set => SetProperty(ref isLoading, value, () => + { + AllowEscape = !value; + AllowEnter = !value; + EnableConfirm = !value; + }); + } + // + // + // + private SolidColorBrush _Underpaint = new SolidColorBrush(Color.FromRgb(238, 238, 238)); + /// + /// 背景底色 + /// + public SolidColorBrush Underpaint + { + get => _Underpaint; + set => SetProperty(ref _Underpaint, value); + } + + public event Action RequestClose; + protected void OnRequestClose(IDialogResult result) + { + RequestClose?.Invoke(result); + } + + public virtual bool CanCloseDialog() + { + return true; + } + + public virtual void OnDialogClosed() + { + + } + + public virtual void OnDialogOpened(IDialogParameters parameters) + { + + } + + public bool EnableConfirm + { + get => _enableConfirm; + set => SetProperty(ref _enableConfirm, value); + } + + public bool ShowConfirm + { + get => _ShowConfirm; + set => SetProperty(ref _ShowConfirm, value); + } + public bool ShowCancel + { + get => _ShowCancel; + set => SetProperty(ref _ShowCancel, value); + } + public bool ShowErrorMsg + { + get => _ShowErrorMsg; + set => SetProperty(ref _ShowErrorMsg, value); + } + + public string ConfirmText + { + get => confirmText; + set => SetProperty(ref confirmText, value); + } + public string CancelText + { + get => cancelText; + set => SetProperty(ref cancelText, value); + } + public string BackText + { + get => backText; + set => SetProperty(ref backText, value); + } + + /// + /// 错误提示 + /// + public string ErrorMsg + { + get => _ErrorMsg; + set => SetProperty(ref _ErrorMsg, value); + } + + public virtual ICommand ConfirmCommand => new DelegateCommand(_Confirm); + + protected virtual void _Confirm() + { + DialogResult ret = Confirm(); + if (ret != null) + { + RequestClose?.Invoke(ret); + } + } + + protected virtual DialogResult Confirm() + { + return new DialogResult(ButtonResult.OK); + } + + public virtual ICommand CancelCommand => new DelegateCommand(_Cancel); + + protected virtual void _Cancel() + { + DialogResult ret = Cancel(); + if (ret != null) + { + RequestClose?.Invoke(ret); + } + else + { + RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); + } + } + protected virtual DialogResult Cancel() + { + return new DialogResult(ButtonResult.Cancel); + } + + public virtual void Loaded(object content) + { + var bb = Application.Current.TryFindResource("BackgroundBrush") as SolidColorBrush; + if (bb != null) + { + Underpaint = bb; + } + + + } + + public class AsyncConfirmDialogViewModel : ConfirmDialogViewModel + { + public override ICommand ConfirmCommand => new AsyncDelegateCommand(_Confirm); + + protected new async Task _Confirm() + { + DialogResult ret = await Confirm(); + if (ret != null) + { + OnRequestClose(ret); + } + } + + protected new virtual async Task Confirm() + { + return await Task.FromResult(new DialogResult(ButtonResult.OK)); + } + } + + public interface IDialogClassParameters + { + + } +} +/// 确定取消对话框 +/// +/// 参数Model +public class ConfirmDialogViewModel : ConfirmDialogViewModel where TParameter : class +{ + protected TParameter Args { get; set; } + public override void OnDialogOpened(IDialogParameters parameters) + { + base.OnDialogOpened(parameters); + if (parameters.TryGetValue("parameter", out TParameter parameter)) + { + Args = parameter; + } + } +} + +public abstract class ConfirmDialogViewModel : ConfirmDialogViewModel where TParameter : class where TResult : DialogResult/*, new()*/ +{ + protected TParameter Args { get; set; } + public override void OnDialogOpened(IDialogParameters parameters) + { + base.OnDialogOpened(parameters); + if (parameters.TryGetValue("parameter", out TParameter parameter)) + { + Args = parameter; + } + } + protected override void _Confirm() + { + TResult ret = Confirm(); + if (ret != null) + { + base.OnRequestClose(ret); + } + } + protected new abstract TResult Confirm(); + + protected override void _Cancel() + { + TResult ret = Cancel(); + if (ret != null) + { + base.OnRequestClose(ret); + } + else + { + base.OnRequestClose(new DialogResult(ButtonResult.Cancel)); + } + } + protected new abstract TResult Cancel(); +} + + +//public abstract class ConfirmDialogParameterViewModel : ConfirmDialogViewModel +//{ +// public abstract class Parameter; +//} \ No newline at end of file diff --git a/Source/MAX.Framework/Extensions/StyleExtensions.cs b/Source/MAX.Framework/Extensions/StyleExtensions.cs new file mode 100644 index 0000000..208c9d2 --- /dev/null +++ b/Source/MAX.Framework/Extensions/StyleExtensions.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace MAX.Framework.Extensions; + +public static class StyleExtensions +{ + /// + /// 合并指定的 。 + /// + /// + /// + public static void Merge(this Style style1, Style style2) + { + if (style1 == null) + { + throw new ArgumentNullException("style1"); + } + if (style2 == null) + { + throw new ArgumentNullException("style2"); + } + + if (style1.TargetType.IsAssignableFrom(style2.TargetType)) + { + style1.TargetType = style2.TargetType; + } + + if (style2.BasedOn != null) + { + style1.Merge(style2.BasedOn); + } + + foreach (SetterBase currentSetter in style2.Setters) + { + style1.Setters.Add(currentSetter); + } + + + foreach (TriggerBase currentTrigger in style2.Triggers) + { + style1.Triggers.Add(currentTrigger); + } + + // This code is only needed when using DynamicResources. + foreach (object key in style2.Resources.Keys) + { + style1.Resources[key] = style2.Resources[key]; + } + } + + /// + /// 集合是否有值。 + /// + /// + /// + /// + public static bool HasValue(this IEnumerable source) + { + return source != null && source.Any(); + } + + public static ResourceDictionary FindResourceDictionary(this Style style, object resourceKey) + { + if (style.Resources != null && style.Resources.Contains(resourceKey)) + { + return style.Resources; + } + if (style.BasedOn != null) + { + return style.BasedOn.FindResourceDictionary(resourceKey); + } + return null; + } + + public static void Merge(this ResourceDictionary resourceDictionary, ResourceDictionary mergee) + { + if (resourceDictionary != null && mergee != null && mergee.Count > 0) + { + foreach (var key in mergee.Keys) + { + if (!resourceDictionary.Contains(key)) + { + resourceDictionary.Add(key, mergee[key]); + } + } + } + } +} diff --git a/Source/Trade.Framework/AssemblyInfo.cs b/Source/Trade.Framework/AssemblyInfo.cs index cdf5d8e..763eb8e 100644 --- a/Source/Trade.Framework/AssemblyInfo.cs +++ b/Source/Trade.Framework/AssemblyInfo.cs @@ -3,6 +3,6 @@ [assembly: XmlnsDefinition("Trade.Framework", "Trade.Framework")] [assembly: XmlnsDefinition("Trade.Framework", "Trade.Framework.Extensions")] [assembly: XmlnsDefinition("Trade.Framework", "Trade.Framework.Controls")] +[assembly: XmlnsDefinition("Trade.Framework", "Trade.Framework.Controls.Attach")] - -[assembly: XmlnsPrefix("Nexus.Framework", "tf")] \ No newline at end of file +[assembly: XmlnsPrefix("WxOrder.Framework", "tf")] \ No newline at end of file diff --git a/Source/Trade.Framework/Controls/Attach/DataGridHelper.cs b/Source/Trade.Framework/Controls/Attach/DataGridHelper.cs new file mode 100644 index 0000000..4587d8b --- /dev/null +++ b/Source/Trade.Framework/Controls/Attach/DataGridHelper.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace Trade.Framework.Controls.Attach; + +public class DataGridHelper +{ + /// + /// + /// + /// + /// + public static string GetNoDataTips(DependencyObject obj) + { + return (string)obj.GetValue(NoDataTipsProperty); + } + + /// + /// + /// + /// + /// + public static void SetNoDataTips(DependencyObject obj, string value) + { + obj.SetValue(NoDataTipsProperty, value); + } + + public static readonly DependencyProperty NoDataTipsProperty = + DependencyProperty.RegisterAttached("NoDataTips", typeof(string), typeof(DataGridHelper),new PropertyMetadata("无数据")); + + /// + /// + /// + /// + /// + public static bool GetIsActive(DependencyObject obj) + { + return (bool)obj.GetValue(IsActiveProperty); + } + + /// + /// + /// + /// + /// + public static void SetIsActive(DependencyObject obj, bool value) + { + obj.SetValue(IsActiveProperty, value); + } + + public static readonly DependencyProperty IsActiveProperty = + DependencyProperty.RegisterAttached("IsActive", typeof(bool), typeof(DataGridHelper)); + +} diff --git a/Source/Trade.Framework/Controls/DialogWindow.xaml b/Source/Trade.Framework/Controls/DialogWindow.xaml new file mode 100644 index 0000000..465d433 --- /dev/null +++ b/Source/Trade.Framework/Controls/DialogWindow.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/Source/Trade.Framework/Controls/DialogWindow.xaml.cs b/Source/Trade.Framework/Controls/DialogWindow.xaml.cs new file mode 100644 index 0000000..df83bed --- /dev/null +++ b/Source/Trade.Framework/Controls/DialogWindow.xaml.cs @@ -0,0 +1,134 @@ +using MAX.Framework.Controls; +using MAX.Framework.Controls.Attach; +using MAX.Framework.Extensions; +using Prism.Services.Dialogs; +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; + +namespace Trade.Framework.Controls; + +/// +/// DialogWindow.xaml 的交互逻辑 +/// +public partial class DialogWindow : WindowBase, IDialogWindow +{ + private readonly Style dialogWindowStyle; + + /// + /// The of the dialog. + /// + 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().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().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); + } +} diff --git a/Source/Trade.Framework/Controls/WindowBase.cs b/Source/Trade.Framework/Controls/WindowBase.cs index 3df51e7..9fc8b17 100644 --- a/Source/Trade.Framework/Controls/WindowBase.cs +++ b/Source/Trade.Framework/Controls/WindowBase.cs @@ -5,13 +5,18 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; +using System.Windows.Media; namespace Trade.Framework.Controls; -public class WindowBase : Window +public class WindowBase : HandyControl.Controls.Window { public WindowBase() { - ViewModelLocator.SetAutoWireViewModel(this, true); + NonClientAreaBackground = FindResource("PrimaryBrush") as Brush; + NonClientAreaForeground = FindResource("TextIconBrush") as Brush; + CloseButtonForeground = FindResource("TextIconBrush") as Brush; + OtherButtonForeground = FindResource("TextIconBrush") as Brush; + BorderThickness = new Thickness(0); } } diff --git a/Source/Trade.Framework/FrameworkApplication.cs b/Source/Trade.Framework/FrameworkApplication.cs index a946aa7..97d6836 100644 --- a/Source/Trade.Framework/FrameworkApplication.cs +++ b/Source/Trade.Framework/FrameworkApplication.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; +using Trade.Framework.Controls; using Trade.Framework.Extensions; namespace Trade.Framework; @@ -28,6 +29,7 @@ public abstract class FrameworkApplication : PrismApplication protected override void OnInitialized() { + (Container as IContainerExtension).RegisterDialog(); base.OnInitialized(); } diff --git a/Source/Trade.Framework/Resources/Theme.xaml b/Source/Trade.Framework/Resources/Theme.xaml new file mode 100644 index 0000000..3474f59 --- /dev/null +++ b/Source/Trade.Framework/Resources/Theme.xaml @@ -0,0 +1,433 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/Source/Trade.Framework/Trade.Framework.csproj b/Source/Trade.Framework/Trade.Framework.csproj index 451d7b3..46dcec7 100644 --- a/Source/Trade.Framework/Trade.Framework.csproj +++ b/Source/Trade.Framework/Trade.Framework.csproj @@ -2,11 +2,14 @@ $(DefaultTargetFramework)-windows + true + + @@ -14,10 +17,5 @@ - - - MSBuild:Compile - - diff --git a/WxOrder.Framework/AssemblyInfo.cs b/WxOrder.Framework/AssemblyInfo.cs new file mode 100644 index 0000000..436594e --- /dev/null +++ b/WxOrder.Framework/AssemblyInfo.cs @@ -0,0 +1,8 @@ +using System.Windows.Markup; + +[assembly: XmlnsDefinition("WxOrder.Framework", "WxOrder.Framework")] +[assembly: XmlnsDefinition("WxOrder.Framework", "WxOrder.Framework.Extensions")] +[assembly: XmlnsDefinition("WxOrder.Framework", "WxOrder.Framework.Controls")] +[assembly: XmlnsDefinition("WxOrder.Framework", "WxOrder.Framework.Controls.Attach")] + +[assembly: XmlnsPrefix("WxOrder.Framework", "tf")] \ No newline at end of file diff --git a/WxOrder.Framework/Controls/Attach/DataGridHelper.cs b/WxOrder.Framework/Controls/Attach/DataGridHelper.cs new file mode 100644 index 0000000..ab6c3ef --- /dev/null +++ b/WxOrder.Framework/Controls/Attach/DataGridHelper.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace WxOrder.Framework.Controls.Attach; + +public class DataGridHelper +{ + /// + /// + /// + /// + /// + public static string GetNoDataTips(DependencyObject obj) + { + return (string)obj.GetValue(NoDataTipsProperty); + } + + /// + /// + /// + /// + /// + public static void SetNoDataTips(DependencyObject obj, string value) + { + obj.SetValue(NoDataTipsProperty, value); + } + + public static readonly DependencyProperty NoDataTipsProperty = + DependencyProperty.RegisterAttached("NoDataTips", typeof(string), typeof(DataGridHelper),new PropertyMetadata("无数据")); + + /// + /// + /// + /// + /// + public static bool GetIsActive(DependencyObject obj) + { + return (bool)obj.GetValue(IsActiveProperty); + } + + /// + /// + /// + /// + /// + public static void SetIsActive(DependencyObject obj, bool value) + { + obj.SetValue(IsActiveProperty, value); + } + + public static readonly DependencyProperty IsActiveProperty = + DependencyProperty.RegisterAttached("IsActive", typeof(bool), typeof(DataGridHelper)); + +} diff --git a/WxOrder.Framework/Resources/Theme.xaml b/WxOrder.Framework/Resources/Theme.xaml index 1cc39a2..91c15fb 100644 --- a/WxOrder.Framework/Resources/Theme.xaml +++ b/WxOrder.Framework/Resources/Theme.xaml @@ -1,7 +1,8 @@  + xmlns:hc="https://handyorg.github.io/handycontrol" + xmlns:tf="WxOrder.Framework"> @@ -26,285 +27,413 @@ - - - - - - - - + + + + + + + + - - - - + - - - - - - - - - - - - - \ No newline at end of file diff --git a/WxOrder.Framework/WxOrder.Framework.csproj b/WxOrder.Framework/WxOrder.Framework.csproj index d418a85..db5f0e7 100644 --- a/WxOrder.Framework/WxOrder.Framework.csproj +++ b/WxOrder.Framework/WxOrder.Framework.csproj @@ -52,7 +52,6 @@ -