From 096fa70ecb128c708307e32808274d4d6e61294a Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Sun, 21 Jun 2020 00:32:16 +0800 Subject: [PATCH 1/4] init branch --- .../HandyControlDemo_Net_40.csproj | 3 ++ .../HandyControlDemo_Net_GE45.csproj | 3 ++ .../HandyControlDemo_Code.csproj | 7 ++++ .../Data/DemoInfo.json | 3 +- .../HandyControlDemo_Shared.projitems | 7 ++++ .../Properties/Langs/Lang.Designer.cs | 13 +++++- .../Properties/Langs/Lang.en.resx | 3 ++ .../Properties/Langs/Lang.fa.resx | 3 ++ .../Properties/Langs/Lang.fr.resx | 3 ++ .../Properties/Langs/Lang.ko-KR.resx | 3 ++ .../Properties/Langs/Lang.resx | 3 ++ .../Properties/Langs/Lang.ru.resx | 3 ++ .../Properties/Langs/Lang.tr.resx | 3 ++ .../Properties/Langs/LangProvider.cs | 13 +++++- .../Img/LeftMainContent/Image_16x.png | Bin 0 -> 298 bytes .../Controls/ImageSelectorDemoCtl.xaml | 9 +++++ .../Controls/ImageSelectorDemoCtl.xaml.cs | 10 +++++ .../UserControl/Main/LeftMainContent.xaml | 2 +- .../UserControl/Main/LeftMainContent.xaml.cs | 16 -------- .../Controls/Input/ImageSelector.cs | 38 ++++++++++++++++++ .../Controls/Other/GotoTop.cs | 2 +- .../Controls/PropertyGrid/PropertyGrid.cs | 4 +- .../Controls/PropertyGrid/PropertyItem.cs | 7 ++-- .../HandyControl_Shared.projitems | 9 +++++ .../Styles/Base/ImageSelectorBaseStyle.xaml | 7 ++++ .../Themes/Styles/ImageSelector.xaml | 11 +++++ .../Themes/Styles/Style.xaml | 1 + 27 files changed, 160 insertions(+), 26 deletions(-) create mode 100644 src/Shared/HandyControlDemo_Shared/Resources/Img/LeftMainContent/Image_16x.png create mode 100644 src/Shared/HandyControlDemo_Shared/UserControl/Controls/ImageSelectorDemoCtl.xaml create mode 100644 src/Shared/HandyControlDemo_Shared/UserControl/Controls/ImageSelectorDemoCtl.xaml.cs create mode 100644 src/Shared/HandyControl_Shared/Controls/Input/ImageSelector.cs create mode 100644 src/Shared/HandyControl_Shared/Themes/Styles/Base/ImageSelectorBaseStyle.xaml create mode 100644 src/Shared/HandyControl_Shared/Themes/Styles/ImageSelector.xaml diff --git a/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj b/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj index c3b5331e..0d0f8565 100644 --- a/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj +++ b/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj @@ -265,6 +265,9 @@ Resources\Img\LeftMainContent\HoverMenu_16x.png + + Resources\Img\LeftMainContent\Image_16x.png + Resources\Img\LeftMainContent\ImageBrowser_16x.png diff --git a/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj b/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj index f03fb5a0..4c0b20e3 100644 --- a/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj +++ b/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj @@ -265,6 +265,9 @@ Resources\Img\LeftMainContent\HoverMenu_16x.png + + Resources\Img\LeftMainContent\Image_16x.png + Resources\Img\LeftMainContent\ImageBrowser_16x.png diff --git a/src/Shared/HandyControlDemo_Code/HandyControlDemo_Code.csproj b/src/Shared/HandyControlDemo_Code/HandyControlDemo_Code.csproj index f17655ca..dbbb46a4 100644 --- a/src/Shared/HandyControlDemo_Code/HandyControlDemo_Code.csproj +++ b/src/Shared/HandyControlDemo_Code/HandyControlDemo_Code.csproj @@ -138,6 +138,9 @@ UserControl\Controls\ImageBrowserDemoCtl.xaml + + UserControl\Controls\ImageSelectorDemoCtl.xaml + UserControl\Controls\LoadingDemoCtl.xaml @@ -523,6 +526,10 @@ UserControl\Controls\ImageBrowserDemoCtl.xaml.cs ImageBrowserDemoCtl.xaml + + UserControl\Controls\ImageSelectorDemoCtl.xaml.cs + ImageSelectorDemoCtl.xaml + UserControl\Controls\LoadingDemoCtl.xaml.cs LoadingDemoCtl.xaml diff --git a/src/Shared/HandyControlDemo_Shared/Data/DemoInfo.json b/src/Shared/HandyControlDemo_Shared/Data/DemoInfo.json index 7ee1eeb7..3f16bf4a 100644 --- a/src/Shared/HandyControlDemo_Shared/Data/DemoInfo.json +++ b/src/Shared/HandyControlDemo_Shared/Data/DemoInfo.json @@ -27,7 +27,7 @@ [ "GroupBox", "GroupBoxDemoCtl", "GroupBox_16x", "" ], [ "Menu", "MenuDemoCtl", "ContextMenu_16x", "" ], [ "RichTextBox", "RichTextBoxDemoCtl", "RichTextBox_16x", "" ], - [ "FlowDocument", "FlowDocumentDemoCtl", "WPFFlowDocument_16x", "1" ], + [ "FlowDocument", "FlowDocumentDemoCtl", "WPFFlowDocument_16x", "" ], [ "ToolBar", "ToolBarDemoCtl", "ToolBar_16x", "" ], [ "Border", "BorderDemoCtl", "BorderElement_16x", "" ], [ "Label", "LabelDemoCtl", "Label_16x", "" ], @@ -41,6 +41,7 @@ "demoItemList": [ [ "FloatingBlock", "FloatingBlockDemoCtl", "thumbs_up", "" ], [ "PropertyGrid", "PropertyGridDemoCtl", "PropertyGridEditorPart_16x", "1" ], + [ "ImageSelector", "ImageSelectorDemoCtl", "Image_16x", "1" ], [ "ImageBlock", "ImageBlockDemoCtl", "ImageStack_16x", "" ], [ "Magnifier", "MagnifierDemoCtl", "Search_16x", "" ], [ "Gravatar", "GravatarDemoCtl", "User_16x", "" ], diff --git a/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems b/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems index 27573381..0e17de7f 100644 --- a/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems +++ b/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems @@ -55,6 +55,9 @@ TextDialogWithTimer.xaml + + ImageSelectorDemoCtl.xaml + AnimationPathDemoCtl.xaml @@ -512,6 +515,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.Designer.cs b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.Designer.cs index d6b6456b..41e738c9 100644 --- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.Designer.cs +++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.Designer.cs @@ -851,7 +851,18 @@ namespace HandyControlDemo.Properties.Langs { return ResourceManager.GetString("ImageBrowser", resourceCulture); } } - + + /// + /// 查找类似 图片选择器 的本地化字符串。 + /// + public static string ImageSelector + { + get + { + return ResourceManager.GetString("ImageSelector", resourceCulture); + } + } + /// /// 查找类似 索引 的本地化字符串。 /// diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.en.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.en.resx index 0f8f8540..c732de69 100644 --- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.en.resx +++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.en.resx @@ -753,4 +753,7 @@ PropertyGrid + + ImageSelector + \ No newline at end of file diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fa.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fa.resx index f176e3e2..55d816c1 100644 --- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fa.resx +++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fa.resx @@ -753,4 +753,7 @@ PropertyGrid + + ImageSelector + \ No newline at end of file diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fr.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fr.resx index 1f15b560..c8d40632 100644 --- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fr.resx +++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fr.resx @@ -753,4 +753,7 @@ PropertyGrid + + ImageSelector + \ No newline at end of file diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ko-KR.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ko-KR.resx index fe9f13ee..145d2134 100644 --- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ko-KR.resx +++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ko-KR.resx @@ -753,4 +753,7 @@ PropertyGrid + + ImageSelector + \ No newline at end of file diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.resx index e876c1bc..1035e112 100644 --- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.resx +++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.resx @@ -753,4 +753,7 @@ 属性编辑器 + + 图片选择器 + \ No newline at end of file diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ru.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ru.resx index 0f8f8540..c732de69 100644 --- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ru.resx +++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ru.resx @@ -753,4 +753,7 @@ PropertyGrid + + ImageSelector + \ No newline at end of file diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.tr.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.tr.resx index f0fb5b5c..988e40aa 100644 --- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.tr.resx +++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.tr.resx @@ -753,4 +753,7 @@ PropertyGrid + + ImageSelector + \ No newline at end of file diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/LangProvider.cs b/src/Shared/HandyControlDemo_Shared/Properties/Langs/LangProvider.cs index e031d4b3..9a7df866 100644 --- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/LangProvider.cs +++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/LangProvider.cs @@ -125,7 +125,8 @@ namespace HandyControlDemo.Properties.Langs OnPropertyChanged(nameof(Ignore)); OnPropertyChanged(nameof(ImageBlock)); OnPropertyChanged(nameof(ImageBrowser)); - OnPropertyChanged(nameof(Index)); + OnPropertyChanged(nameof(ImageSelector)); + OnPropertyChanged(nameof(Index)); OnPropertyChanged(nameof(Info)); OnPropertyChanged(nameof(InteractiveDialog)); OnPropertyChanged(nameof(IsNotPhone)); @@ -691,6 +692,11 @@ namespace HandyControlDemo.Properties.Langs /// public string ImageBrowser => Lang.ImageBrowser; + /// + /// 查找类似 图片选择器 的本地化字符串。 + /// + public string ImageSelector => Lang.ImageSelector; + /// /// 查找类似 索引 的本地化字符串。 /// @@ -1760,6 +1766,11 @@ namespace HandyControlDemo.Properties.Langs /// public static string ImageBrowser = nameof(ImageBrowser); + /// + /// 查找类似 图片选择器 的本地化字符串。 + /// + public static string ImageSelector = nameof(ImageSelector); + /// /// 查找类似 索引 的本地化字符串。 /// diff --git a/src/Shared/HandyControlDemo_Shared/Resources/Img/LeftMainContent/Image_16x.png b/src/Shared/HandyControlDemo_Shared/Resources/Img/LeftMainContent/Image_16x.png new file mode 100644 index 0000000000000000000000000000000000000000..b6084a351aecbd4103f1e13814396940454d9cfe GIT binary patch literal 298 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9F5M?jcysy3fAQ1FhY zi(^Pd+|mhqyAC;swE8>o+~8=M?dJ046PMXa9p--zr8zQdn7*5C*}SQ|oLRHBeT$%@ zz(z@KMb}NUb=`Jc^$-$Pk1x(Ewma7&y--OW@y?_Tdn|L?f5Wx-b8(~QYH tT2B^SZA&Q^u)LzeEMa=mWhjmg{ + + + + diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/ImageSelectorDemoCtl.xaml.cs b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/ImageSelectorDemoCtl.xaml.cs new file mode 100644 index 00000000..b71a7746 --- /dev/null +++ b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/ImageSelectorDemoCtl.xaml.cs @@ -0,0 +1,10 @@ +namespace HandyControlDemo.UserControl +{ + public partial class ImageSelectorDemoCtl + { + public ImageSelectorDemoCtl() + { + InitializeComponent(); + } + } +} diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Main/LeftMainContent.xaml b/src/Shared/HandyControlDemo_Shared/UserControl/Main/LeftMainContent.xaml index 637f5961..cf4160b3 100644 --- a/src/Shared/HandyControlDemo_Shared/UserControl/Main/LeftMainContent.xaml +++ b/src/Shared/HandyControlDemo_Shared/UserControl/Main/LeftMainContent.xaml @@ -44,7 +44,7 @@ - + diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Main/LeftMainContent.xaml.cs b/src/Shared/HandyControlDemo_Shared/UserControl/Main/LeftMainContent.xaml.cs index 65d6519d..3ddd5898 100644 --- a/src/Shared/HandyControlDemo_Shared/UserControl/Main/LeftMainContent.xaml.cs +++ b/src/Shared/HandyControlDemo_Shared/UserControl/Main/LeftMainContent.xaml.cs @@ -2,7 +2,6 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; -using HandyControl.Controls; using HandyControl.Data; using HandyControlDemo.Data; using HandyControlDemo.ViewModel; @@ -87,20 +86,5 @@ namespace HandyControlDemo.UserControl } } } - - private void SearchBar_OnTextChanged(object sender, TextChangedEventArgs e) - { - if (e.OriginalSource is SearchBar searchBar) - { - _searchKey = searchBar.Text; - if (string.IsNullOrEmpty(_searchKey)) - { - foreach (var item in ViewModelLocator.Instance.Main.DemoInfoCurrent.DemoItemList) - { - item.IsVisible = true; - } - } - } - } } } \ No newline at end of file diff --git a/src/Shared/HandyControl_Shared/Controls/Input/ImageSelector.cs b/src/Shared/HandyControl_Shared/Controls/Input/ImageSelector.cs new file mode 100644 index 00000000..f6b34b8d --- /dev/null +++ b/src/Shared/HandyControl_Shared/Controls/Input/ImageSelector.cs @@ -0,0 +1,38 @@ +using System; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; +using HandyControl.Data; + +namespace HandyControl.Controls +{ + public class ImageSelector : Control + { + public static readonly DependencyProperty UriProperty = DependencyProperty.Register( + "Uri", typeof(Uri), typeof(ImageSelector), new PropertyMetadata(default(Uri))); + + public Uri Uri + { + get => (Uri) GetValue(UriProperty); + set => SetValue(UriProperty, value); + } + + internal static readonly DependencyProperty SourceProperty = DependencyProperty.Register( + "Source", typeof(ImageSource), typeof(ImageSelector), new PropertyMetadata(default(ImageSource))); + + internal ImageSource Source + { + get => (ImageSource) GetValue(SourceProperty); + set => SetValue(SourceProperty, value); + } + + public static readonly DependencyProperty IsPreviewEnabledProperty = DependencyProperty.Register( + "IsPreviewEnabled", typeof(bool), typeof(ImageSelector), new PropertyMetadata(ValueBoxes.FalseBox)); + + public bool IsPreviewEnabled + { + get => (bool) GetValue(IsPreviewEnabledProperty); + set => SetValue(IsPreviewEnabledProperty, value); + } + } +} \ No newline at end of file diff --git a/src/Shared/HandyControl_Shared/Controls/Other/GotoTop.cs b/src/Shared/HandyControl_Shared/Controls/Other/GotoTop.cs index 0d5ea363..d7acb02e 100644 --- a/src/Shared/HandyControl_Shared/Controls/Other/GotoTop.cs +++ b/src/Shared/HandyControl_Shared/Controls/Other/GotoTop.cs @@ -73,7 +73,7 @@ namespace HandyControl.Controls } public static readonly DependencyProperty HidingHeightProperty = DependencyProperty.Register( - "HidingHeight", typeof(double), typeof(GotoTop), new PropertyMetadata(default(double))); + "HidingHeight", typeof(double), typeof(GotoTop), new PropertyMetadata(ValueBoxes.Double0Box)); public double HidingHeight { diff --git a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyGrid.cs b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyGrid.cs index 37a5a2c6..1ac9e1ed 100644 --- a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyGrid.cs +++ b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyGrid.cs @@ -76,7 +76,7 @@ namespace HandyControl.Controls } public static readonly DependencyProperty MaxTitleWidthProperty = DependencyProperty.Register( - "MaxTitleWidth", typeof(double), typeof(PropertyGrid), new PropertyMetadata(default(double))); + "MaxTitleWidth", typeof(double), typeof(PropertyGrid), new PropertyMetadata(ValueBoxes.Double0Box)); public double MaxTitleWidth { @@ -85,7 +85,7 @@ namespace HandyControl.Controls } public static readonly DependencyProperty MinTitleWidthProperty = DependencyProperty.Register( - "MinTitleWidth", typeof(double), typeof(PropertyGrid), new PropertyMetadata(default(double))); + "MinTitleWidth", typeof(double), typeof(PropertyGrid), new PropertyMetadata(ValueBoxes.Double0Box)); public double MinTitleWidth { diff --git a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyItem.cs b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyItem.cs index be9bfc25..3ef9888a 100644 --- a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyItem.cs +++ b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyItem.cs @@ -2,6 +2,7 @@ using System.ComponentModel; using System.Windows; using System.Windows.Controls; +using HandyControl.Data; namespace HandyControl.Controls { @@ -62,7 +63,7 @@ namespace HandyControl.Controls } public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty.Register( - "IsReadOnly", typeof(bool), typeof(PropertyItem), new PropertyMetadata(default(bool))); + "IsReadOnly", typeof(bool), typeof(PropertyItem), new PropertyMetadata(ValueBoxes.FalseBox)); public bool IsReadOnly { @@ -107,7 +108,7 @@ namespace HandyControl.Controls } public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register( - "IsSelected", typeof(bool), typeof(PropertyItem), new PropertyMetadata(default(bool))); + "IsSelected", typeof(bool), typeof(PropertyItem), new PropertyMetadata(ValueBoxes.FalseBox)); public bool IsSelected { @@ -116,7 +117,7 @@ namespace HandyControl.Controls } public static readonly DependencyProperty IsExpandedEnabledProperty = DependencyProperty.Register( - "IsExpandedEnabled", typeof(bool), typeof(PropertyItem), new PropertyMetadata(default(bool))); + "IsExpandedEnabled", typeof(bool), typeof(PropertyItem), new PropertyMetadata(ValueBoxes.FalseBox)); public bool IsExpandedEnabled { diff --git a/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems b/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems index f2dc54a6..3b30bb3a 100644 --- a/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems +++ b/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems @@ -31,6 +31,7 @@ + @@ -436,6 +437,14 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/src/Shared/HandyControl_Shared/Themes/Styles/Base/ImageSelectorBaseStyle.xaml b/src/Shared/HandyControl_Shared/Themes/Styles/Base/ImageSelectorBaseStyle.xaml new file mode 100644 index 00000000..9e7d50cb --- /dev/null +++ b/src/Shared/HandyControl_Shared/Themes/Styles/Base/ImageSelectorBaseStyle.xaml @@ -0,0 +1,7 @@ + + + \ No newline at end of file diff --git a/src/Shared/HandyControl_Shared/Themes/Styles/Image.xaml b/src/Shared/HandyControl_Shared/Themes/Styles/Image.xaml index 12c5dff7..1e115576 100644 --- a/src/Shared/HandyControl_Shared/Themes/Styles/Image.xaml +++ b/src/Shared/HandyControl_Shared/Themes/Styles/Image.xaml @@ -2,7 +2,7 @@ \ No newline at end of file diff --git a/src/Shared/HandyControl_Shared/Tools/Extension/ValueExtension.cs b/src/Shared/HandyControl_Shared/Tools/Extension/ValueExtension.cs index c4606424..78afef86 100644 --- a/src/Shared/HandyControl_Shared/Tools/Extension/ValueExtension.cs +++ b/src/Shared/HandyControl_Shared/Tools/Extension/ValueExtension.cs @@ -1,9 +1,21 @@ using System.Windows; +using HandyControl.Expression.Drawing; namespace HandyControl.Tools.Extension { public static class ValueExtension { public static Thickness Add(this Thickness a, Thickness b) => new Thickness(a.Left + b.Left, a.Top + b.Top, a.Right + b.Right, a.Bottom + b.Bottom); + + public static bool IsZero(this Thickness thickness) => + MathHelper.IsZero(thickness.Left) + && MathHelper.IsZero(thickness.Top) + && MathHelper.IsZero(thickness.Right) + && MathHelper.IsZero(thickness.Bottom); + + public static bool IsUniform(this Thickness thickness) => + MathHelper.AreClose(thickness.Left, thickness.Top) + && MathHelper.AreClose(thickness.Left, thickness.Right) + && MathHelper.AreClose(thickness.Left, thickness.Bottom); } } \ No newline at end of file diff --git a/src/Shared/HandyControl_Shared/Tools/GifImageAnimator.cs b/src/Shared/HandyControl_Shared/Tools/GifImageAnimator.cs index 2c6a58b3..9f3a6671 100644 --- a/src/Shared/HandyControl_Shared/Tools/GifImageAnimator.cs +++ b/src/Shared/HandyControl_Shared/Tools/GifImageAnimator.cs @@ -92,10 +92,7 @@ namespace HandyControl.Tools { // Construct the image array // - if (ImageInfoList == null) - { - ImageInfoList = new List(); - } + ImageInfoList ??= new List(); // Add the new image // @@ -108,7 +105,7 @@ namespace HandyControl.Tools { AnimationThread = new Thread(AnimateImages50Ms) { - Name = typeof(ImageAnimator).Name, + Name = nameof(ImageAnimator), IsBackground = true }; AnimationThread.Start(); @@ -168,13 +165,18 @@ namespace HandyControl.Tools if (Equals(image, imageInfo.Image)) { - if ((onFrameChangedHandler == imageInfo.FrameChangedHandler) || (onFrameChangedHandler != null && onFrameChangedHandler.Equals(imageInfo.FrameChangedHandler))) + if (onFrameChangedHandler == imageInfo.FrameChangedHandler || onFrameChangedHandler != null && onFrameChangedHandler.Equals(imageInfo.FrameChangedHandler)) { ImageInfoList.Remove(imageInfo); } break; } } + + if (!ImageInfoList.Any()) + { + AnimationThread = null; + } } finally { @@ -224,7 +226,7 @@ namespace HandyControl.Tools [SuppressMessage("Microsoft.Performance", "CA1804:RemoveUnusedLocals")] private static void AnimateImages50Ms() { - while (true) + while (ImageInfoList.Any()) { // Acquire reader-lock to access imageInfoList, elemens in the list can be modified w/o needing a writer-lock. // Observe that we don't need to check if the thread is waiting or a writer lock here since the thread this diff --git a/src/Shared/HandyControl_Shared/Tools/Helper/DpiHelper.cs b/src/Shared/HandyControl_Shared/Tools/Helper/DpiHelper.cs index 623bd29a..7f56eb4b 100644 --- a/src/Shared/HandyControl_Shared/Tools/Helper/DpiHelper.cs +++ b/src/Shared/HandyControl_Shared/Tools/Helper/DpiHelper.cs @@ -1,6 +1,7 @@ using System; using System.Windows; using System.Windows.Media; +using HandyControl.Expression.Drawing; using HandyControl.Tools.Interop; namespace HandyControl.Tools @@ -79,5 +80,25 @@ namespace HandyControl.Tools result.Transform(TransformFromDevice.Matrix); return result; } + + public static double RoundLayoutValue(double value, double dpiScale) + { + double newValue; + + if (!MathHelper.AreClose(dpiScale, 1.0)) + { + newValue = Math.Round(value * dpiScale) / dpiScale; + if (double.IsNaN(newValue) || double.IsInfinity(newValue) || MathHelper.AreClose(newValue, double.MaxValue)) + { + newValue = value; + } + } + else + { + newValue = Math.Round(value); + } + + return newValue; + } } } \ No newline at end of file