From bce4cacf1122a5a4f43bb767c4c8de67c2bbc8b8 Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Thu, 27 Dec 2018 17:05:05 +0800 Subject: [PATCH] add AboutWindow --- HandyControl.sln | 10 ++++ .../Controls/{Other => Image}/GifImage.cs | 0 .../Controls/{Other => Image}/ImageViewer.cs | 0 HandyControl/Controls/Other/RadioGroup.cs | 9 --- .../Controls/{Other => Panel}/CirclePanel.cs | 0 HandyControl/Controls/Rate/Rate.cs | 2 +- HandyControl/Controls/Text/OutlineText.cs | 2 +- HandyControl/Controls/Window/Window.cs | 2 +- HandyControl/HandyControl.csproj | 39 ++++++++---- HandyControl/Tools/Helper/DesignerHelper.cs | 59 ++++--------------- HandyControlDemo/HandyControlDemo.csproj | 18 ++++++ .../UserControl/Main/NoUserContent.xaml | 1 + .../UserControl/Main/NoUserContent.xaml.cs | 9 +++ .../ViewModel/WindowDemoViewModel.cs | 2 + HandyControlDemo/Window/AboutWindow.xaml | 31 ++++++++++ HandyControlDemo/Window/AboutWindow.xaml.cs | 38 ++++++++++++ 16 files changed, 151 insertions(+), 71 deletions(-) rename HandyControl/Controls/{Other => Image}/GifImage.cs (100%) rename HandyControl/Controls/{Other => Image}/ImageViewer.cs (100%) rename HandyControl/Controls/{Other => Panel}/CirclePanel.cs (100%) create mode 100644 HandyControlDemo/Window/AboutWindow.xaml create mode 100644 HandyControlDemo/Window/AboutWindow.xaml.cs diff --git a/HandyControl.sln b/HandyControl.sln index a23bfefb..d8dca9bf 100644 --- a/HandyControl.sln +++ b/HandyControl.sln @@ -12,9 +12,11 @@ Global Debug|Any CPU = Debug|Any CPU Debug-Net40|Any CPU = Debug-Net40|Any CPU Debug-Net45|Any CPU = Debug-Net45|Any CPU + Debug-Net47|Any CPU = Debug-Net47|Any CPU Release|Any CPU = Release|Any CPU Release-Net40|Any CPU = Release-Net40|Any CPU Release-Net45|Any CPU = Release-Net45|Any CPU + Release-Net47|Any CPU = Release-Net47|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {DC966E3D-BCFF-4652-98CF-070E5494749A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -23,24 +25,32 @@ Global {DC966E3D-BCFF-4652-98CF-070E5494749A}.Debug-Net40|Any CPU.Build.0 = Debug-Net40|Any CPU {DC966E3D-BCFF-4652-98CF-070E5494749A}.Debug-Net45|Any CPU.ActiveCfg = Debug-Net45|Any CPU {DC966E3D-BCFF-4652-98CF-070E5494749A}.Debug-Net45|Any CPU.Build.0 = Debug-Net45|Any CPU + {DC966E3D-BCFF-4652-98CF-070E5494749A}.Debug-Net47|Any CPU.ActiveCfg = Debug-Net47|Any CPU + {DC966E3D-BCFF-4652-98CF-070E5494749A}.Debug-Net47|Any CPU.Build.0 = Debug-Net47|Any CPU {DC966E3D-BCFF-4652-98CF-070E5494749A}.Release|Any CPU.ActiveCfg = Release|Any CPU {DC966E3D-BCFF-4652-98CF-070E5494749A}.Release|Any CPU.Build.0 = Release|Any CPU {DC966E3D-BCFF-4652-98CF-070E5494749A}.Release-Net40|Any CPU.ActiveCfg = Release-Net40|Any CPU {DC966E3D-BCFF-4652-98CF-070E5494749A}.Release-Net40|Any CPU.Build.0 = Release-Net40|Any CPU {DC966E3D-BCFF-4652-98CF-070E5494749A}.Release-Net45|Any CPU.ActiveCfg = Release-Net45|Any CPU {DC966E3D-BCFF-4652-98CF-070E5494749A}.Release-Net45|Any CPU.Build.0 = Release-Net45|Any CPU + {DC966E3D-BCFF-4652-98CF-070E5494749A}.Release-Net47|Any CPU.ActiveCfg = Release-Net47|Any CPU + {DC966E3D-BCFF-4652-98CF-070E5494749A}.Release-Net47|Any CPU.Build.0 = Release-Net47|Any CPU {9A7B52E6-94BB-4E7E-BB6A-7CF6761B79A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {9A7B52E6-94BB-4E7E-BB6A-7CF6761B79A7}.Debug|Any CPU.Build.0 = Debug|Any CPU {9A7B52E6-94BB-4E7E-BB6A-7CF6761B79A7}.Debug-Net40|Any CPU.ActiveCfg = Debug|Any CPU {9A7B52E6-94BB-4E7E-BB6A-7CF6761B79A7}.Debug-Net40|Any CPU.Build.0 = Debug|Any CPU {9A7B52E6-94BB-4E7E-BB6A-7CF6761B79A7}.Debug-Net45|Any CPU.ActiveCfg = Debug|Any CPU {9A7B52E6-94BB-4E7E-BB6A-7CF6761B79A7}.Debug-Net45|Any CPU.Build.0 = Debug|Any CPU + {9A7B52E6-94BB-4E7E-BB6A-7CF6761B79A7}.Debug-Net47|Any CPU.ActiveCfg = Debug|Any CPU + {9A7B52E6-94BB-4E7E-BB6A-7CF6761B79A7}.Debug-Net47|Any CPU.Build.0 = Debug|Any CPU {9A7B52E6-94BB-4E7E-BB6A-7CF6761B79A7}.Release|Any CPU.ActiveCfg = Release|Any CPU {9A7B52E6-94BB-4E7E-BB6A-7CF6761B79A7}.Release|Any CPU.Build.0 = Release|Any CPU {9A7B52E6-94BB-4E7E-BB6A-7CF6761B79A7}.Release-Net40|Any CPU.ActiveCfg = Release|Any CPU {9A7B52E6-94BB-4E7E-BB6A-7CF6761B79A7}.Release-Net40|Any CPU.Build.0 = Release|Any CPU {9A7B52E6-94BB-4E7E-BB6A-7CF6761B79A7}.Release-Net45|Any CPU.ActiveCfg = Release|Any CPU {9A7B52E6-94BB-4E7E-BB6A-7CF6761B79A7}.Release-Net45|Any CPU.Build.0 = Release|Any CPU + {9A7B52E6-94BB-4E7E-BB6A-7CF6761B79A7}.Release-Net47|Any CPU.ActiveCfg = Release-Net47|Any CPU + {9A7B52E6-94BB-4E7E-BB6A-7CF6761B79A7}.Release-Net47|Any CPU.Build.0 = Release-Net47|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/HandyControl/Controls/Other/GifImage.cs b/HandyControl/Controls/Image/GifImage.cs similarity index 100% rename from HandyControl/Controls/Other/GifImage.cs rename to HandyControl/Controls/Image/GifImage.cs diff --git a/HandyControl/Controls/Other/ImageViewer.cs b/HandyControl/Controls/Image/ImageViewer.cs similarity index 100% rename from HandyControl/Controls/Other/ImageViewer.cs rename to HandyControl/Controls/Image/ImageViewer.cs diff --git a/HandyControl/Controls/Other/RadioGroup.cs b/HandyControl/Controls/Other/RadioGroup.cs index 86f957f7..97b9bc38 100644 --- a/HandyControl/Controls/Other/RadioGroup.cs +++ b/HandyControl/Controls/Other/RadioGroup.cs @@ -10,15 +10,6 @@ namespace HandyControl.Controls protected override bool IsItemItsOwnContainerOverride(object item) => item is RadioButton; - //public static readonly DependencyProperty GroupNameProperty = DependencyProperty.Register( - // "GroupName", typeof(string), typeof(RadioGroup), new PropertyMetadata(default(string))); - - //public string GroupName - //{ - // get => (string) GetValue(GroupNameProperty); - // set => SetValue(GroupNameProperty, value); - //} - public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register( "Orientation", typeof(Orientation), typeof(RadioGroup), new PropertyMetadata(default(Orientation))); diff --git a/HandyControl/Controls/Other/CirclePanel.cs b/HandyControl/Controls/Panel/CirclePanel.cs similarity index 100% rename from HandyControl/Controls/Other/CirclePanel.cs rename to HandyControl/Controls/Panel/CirclePanel.cs diff --git a/HandyControl/Controls/Rate/Rate.cs b/HandyControl/Controls/Rate/Rate.cs index d41d3256..d35524f0 100644 --- a/HandyControl/Controls/Rate/Rate.cs +++ b/HandyControl/Controls/Rate/Rate.cs @@ -52,7 +52,7 @@ namespace HandyControl.Controls Loaded += (s, e) => { - if (DesignerHelper.IsInDesignMode()) return; + if (DesignerHelper.IsInDesignMode) return; if (_isLoaded) return; _isLoaded = true; if (Value <= 0) diff --git a/HandyControl/Controls/Text/OutlineText.cs b/HandyControl/Controls/Text/OutlineText.cs index 9cd6c36f..be9022c9 100644 --- a/HandyControl/Controls/Text/OutlineText.cs +++ b/HandyControl/Controls/Text/OutlineText.cs @@ -153,7 +153,7 @@ namespace HandyControl.Controls return; } -#if net45 || net40 +#if netle45 _formattedText = new FormattedText( Text, CultureInfo.CurrentUICulture, diff --git a/HandyControl/Controls/Window/Window.cs b/HandyControl/Controls/Window/Window.cs index a4dc30a4..daa24f1a 100644 --- a/HandyControl/Controls/Window/Window.cs +++ b/HandyControl/Controls/Window/Window.cs @@ -6,7 +6,7 @@ using System.Windows.Input; using System.Windows.Media; using HandyControl.Data; using HandyControl.Tools; -#if net40 +#if netle40 using Microsoft.Windows.Shell; #else using System.Windows.Shell; diff --git a/HandyControl/HandyControl.csproj b/HandyControl/HandyControl.csproj index 5a45f7e2..4b9efcc6 100644 --- a/HandyControl/HandyControl.csproj +++ b/HandyControl/HandyControl.csproj @@ -26,12 +26,23 @@ v4.6.2 netgt40 + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + v4.7 + netgt40 + true full false bin\Debug\ - DEBUG;TRACE;net45 + DEBUG;TRACE;netle45 prompt 4 v4.5 @@ -42,7 +53,7 @@ full false bin\Debug\ - DEBUG;TRACE;net40 + DEBUG;TRACE;netle45;netle40 prompt 4 v4.0 @@ -59,11 +70,22 @@ v4.6.2 netgt40 + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + bin\Release\HandyControl.xml + v4.7 + netgt40 + pdbonly true bin\Release\ - TRACE;net45 + TRACE;netle45 prompt 4 bin\Release\HandyControl.xml @@ -74,7 +96,7 @@ pdbonly true bin\Release\ - TRACE;net40 + TRACE;netle45;netle40 prompt 4 bin\Release\HandyControl.xml @@ -108,14 +130,14 @@ - + - + @@ -123,7 +145,7 @@ - + @@ -721,9 +743,6 @@ - - - diff --git a/HandyControl/Tools/Helper/DesignerHelper.cs b/HandyControl/Tools/Helper/DesignerHelper.cs index 1f4d3416..7a92c9a0 100644 --- a/HandyControl/Tools/Helper/DesignerHelper.cs +++ b/HandyControl/Tools/Helper/DesignerHelper.cs @@ -1,60 +1,21 @@ -using System; -using System.Linq; -using System.Reflection; +using System.ComponentModel; +using System.Windows; namespace HandyControl.Tools { public class DesignerHelper { - public static bool IsInDesignMode() + private static bool? _isInDesignMode; + + public static bool IsInDesignMode { - try + get { - var type1 = Type.GetType( - "System.ComponentModel.DesignerProperties, PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); - if (type1 == null) - return false; - var obj1 = type1.GetTypeInfo().GetDeclaredField("IsInDesignModeProperty").GetValue(null); - var type2 = Type.GetType( - "System.ComponentModel.DependencyPropertyDescriptor, WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); - var type3 = Type.GetType( - "System.Windows.FrameworkElement, PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); - if (type2 == null || type3 == null) - return false; - var list = type2.GetTypeInfo().GetDeclaredMethods("FromProperty").ToList(); - if (list.Count == 0) - return false; - var methodInfo = list.FirstOrDefault(mi => + if (!_isInDesignMode.HasValue) { - if (mi.IsPublic && mi.IsStatic) - return mi.GetParameters().Length == 2; - return false; - }); - if (methodInfo == null) - return false; - var obj2 = methodInfo.Invoke(null, new[] - { - obj1, - type3 - }); - if (obj2 == null) - return false; - var declaredProperty1 = type2.GetTypeInfo().GetDeclaredProperty("Metadata"); - if (declaredProperty1 == null) - return false; - var obj3 = declaredProperty1.GetValue(obj2, null); - var type4 = Type.GetType( - "System.Windows.PropertyMetadata, WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); - if (obj3 == null || type4 == null) - return false; - var declaredProperty2 = type4.GetTypeInfo().GetDeclaredProperty("DefaultValue"); - if (declaredProperty2 == null) - return false; - return (bool) declaredProperty2.GetValue(obj3, null); - } - catch - { - return false; + _isInDesignMode = (bool)DependencyPropertyDescriptor.FromProperty(DesignerProperties.IsInDesignModeProperty, typeof(FrameworkElement)).Metadata.DefaultValue; + } + return _isInDesignMode.Value; } } } diff --git a/HandyControlDemo/HandyControlDemo.csproj b/HandyControlDemo/HandyControlDemo.csproj index 7b854b59..28172c88 100644 --- a/HandyControlDemo/HandyControlDemo.csproj +++ b/HandyControlDemo/HandyControlDemo.csproj @@ -37,6 +37,16 @@ 4 v4.6.2 + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + v4.7 + Resources\Img\icon.ico @@ -297,6 +307,9 @@ + + AboutWindow.xaml + BlurWindow.xaml @@ -614,6 +627,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -718,6 +735,7 @@ + diff --git a/HandyControlDemo/UserControl/Main/NoUserContent.xaml b/HandyControlDemo/UserControl/Main/NoUserContent.xaml index 80dd2517..c4b36c88 100644 --- a/HandyControlDemo/UserControl/Main/NoUserContent.xaml +++ b/HandyControlDemo/UserControl/Main/NoUserContent.xaml @@ -56,6 +56,7 @@ + diff --git a/HandyControlDemo/UserControl/Main/NoUserContent.xaml.cs b/HandyControlDemo/UserControl/Main/NoUserContent.xaml.cs index cd06d767..efa015e0 100644 --- a/HandyControlDemo/UserControl/Main/NoUserContent.xaml.cs +++ b/HandyControlDemo/UserControl/Main/NoUserContent.xaml.cs @@ -8,6 +8,7 @@ using HandyControl.Controls; using HandyControl.Data; using HandyControlDemo.Data; using HandyControlDemo.Tools; +using HandyControlDemo.Window; // ReSharper disable once CheckNamespace namespace HandyControlDemo.UserControl @@ -72,5 +73,13 @@ namespace HandyControlDemo.UserControl Messenger.Default.Send(true, MessageToken.FullSwitch); Messenger.Default.Send(AssemblyHelper.CreateInternalInstance($"UserControl.{MessageToken.ContributorsView}"), MessageToken.LoadShowContent); } + + private void MenuAbout_OnClick(object sender, RoutedEventArgs e) + { + new AboutWindow + { + Owner = Application.Current.MainWindow + }.ShowDialog(); + } } } diff --git a/HandyControlDemo/ViewModel/WindowDemoViewModel.cs b/HandyControlDemo/ViewModel/WindowDemoViewModel.cs index 3c251ddb..9e694c94 100644 --- a/HandyControlDemo/ViewModel/WindowDemoViewModel.cs +++ b/HandyControlDemo/ViewModel/WindowDemoViewModel.cs @@ -1,4 +1,5 @@ using System; +using System.Windows; using GalaSoft.MvvmLight.CommandWpf; using HandyControlDemo.Tools; @@ -12,6 +13,7 @@ namespace HandyControlDemo.ViewModel { if (AssemblyHelper.CreateInternalInstance($"Window.{windowTag}") is System.Windows.Window window) { + window.Owner = Application.Current.MainWindow; window.ShowDialog(); } } diff --git a/HandyControlDemo/Window/AboutWindow.xaml b/HandyControlDemo/Window/AboutWindow.xaml new file mode 100644 index 00000000..63b0d8ab --- /dev/null +++ b/HandyControlDemo/Window/AboutWindow.xaml @@ -0,0 +1,31 @@ + + + + + + + + + diff --git a/HandyControlDemo/Window/AboutWindow.xaml.cs b/HandyControlDemo/Window/AboutWindow.xaml.cs new file mode 100644 index 00000000..3b465a63 --- /dev/null +++ b/HandyControlDemo/Window/AboutWindow.xaml.cs @@ -0,0 +1,38 @@ +using System.Diagnostics; +using System.Reflection; +using System.Windows; + +namespace HandyControlDemo.Window +{ + public partial class AboutWindow + { + public AboutWindow() + { + InitializeComponent(); + + DataContext = this; + + var versionInfo = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location); + CopyRight = versionInfo.LegalCopyright; + Version = $"v {versionInfo.FileVersion}"; + } + + public static readonly DependencyProperty CopyRightProperty = DependencyProperty.Register( + "CopyRight", typeof(string), typeof(AboutWindow), new PropertyMetadata(default(string))); + + public string CopyRight + { + get => (string) GetValue(CopyRightProperty); + set => SetValue(CopyRightProperty, value); + } + + public static readonly DependencyProperty VersionProperty = DependencyProperty.Register( + "Version", typeof(string), typeof(AboutWindow), new PropertyMetadata(default(string))); + + public string Version + { + get => (string) GetValue(VersionProperty); + set => SetValue(VersionProperty, value); + } + } +}