From 875b7eb30ae5c923346c92a60a0254b83dc43ce4 Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Sun, 23 Dec 2018 15:39:50 +0800 Subject: [PATCH] support for .NET framework 4.0 --- HandyControl.sln | 19 +- .../Controls/Attach/DataGridAttach.cs | 11 +- HandyControl/Controls/Other/ColorPicker.cs | 9 +- HandyControl/Controls/Text/OutlineText.cs | 2 +- .../Controls/Window/WindowBorderless.cs | 6 +- HandyControl/HandyControl.csproj | 78 +++++- .../Themes/Styles/Base/ComboBoxBaseStyle.xaml | 40 +-- HandyControl/Themes/Styles/DataGrid.xaml | 4 +- HandyControl/Themes/Styles/ListView.xaml | 4 +- HandyControl/Themes/Styles/Style-Net40.xaml | 53 ++++ HandyControl/Themes/Styles/TreeView.xaml | 10 +- HandyControl/Themes/Styles/Window-Net40.xaml | 251 ++++++++++++++++++ HandyControl/Themes/Styles/Window-net40.tt | 251 ++++++++++++++++++ HandyControl/Themes/Styles/Window-netgt40.tt | 250 +++++++++++++++++ HandyControl/Themes/Styles/Window.tt | 3 + HandyControl/Themes/Styles/Window.xaml | 2 +- HandyControl/packages.config | 5 + HandyControlDemo/HandyControlDemo.csproj | 20 +- HandyControlDemo/Window/CommonWindow.xaml | 3 +- HandyControlDemo/packages.config | 1 + 20 files changed, 957 insertions(+), 65 deletions(-) create mode 100644 HandyControl/Themes/Styles/Style-Net40.xaml create mode 100644 HandyControl/Themes/Styles/Window-Net40.xaml create mode 100644 HandyControl/Themes/Styles/Window-net40.tt create mode 100644 HandyControl/Themes/Styles/Window-netgt40.tt create mode 100644 HandyControl/Themes/Styles/Window.tt create mode 100644 HandyControl/packages.config diff --git a/HandyControl.sln b/HandyControl.sln index 51457f1d..a23bfefb 100644 --- a/HandyControl.sln +++ b/HandyControl.sln @@ -10,22 +10,37 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug-Net40|Any CPU = Debug-Net40|Any CPU Debug-Net45|Any CPU = Debug-Net45|Any CPU Release|Any CPU = Release|Any CPU + Release-Net40|Any CPU = Release-Net40|Any CPU + Release-Net45|Any CPU = Release-Net45|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {DC966E3D-BCFF-4652-98CF-070E5494749A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {DC966E3D-BCFF-4652-98CF-070E5494749A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DC966E3D-BCFF-4652-98CF-070E5494749A}.Debug-Net40|Any CPU.ActiveCfg = Debug-Net40|Any CPU + {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}.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 {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-Net45|Any CPU.ActiveCfg = Debug-Net45|Any CPU - {9A7B52E6-94BB-4E7E-BB6A-7CF6761B79A7}.Debug-Net45|Any CPU.Build.0 = Debug-Net45|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}.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 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/HandyControl/Controls/Attach/DataGridAttach.cs b/HandyControl/Controls/Attach/DataGridAttach.cs index 7d49181f..42348946 100644 --- a/HandyControl/Controls/Attach/DataGridAttach.cs +++ b/HandyControl/Controls/Attach/DataGridAttach.cs @@ -233,21 +233,20 @@ namespace HandyControl.Controls dataGrid.ItemContainerGenerator.ItemsChanged -= ItemContainerGenerator_ItemsChanged; } - UpdateItems(dataGrid.ItemContainerGenerator, show); + UpdateItems(dataGrid.ItemContainerGenerator, dataGrid.Items.Count, show); } private static void ItemContainerGenerator_ItemsChanged(object sender, ItemsChangedEventArgs e) { if (!(sender is ItemContainerGenerator generator)) return; - UpdateItems(generator); + UpdateItems(generator, e.ItemCount); } - private static void UpdateItems(ItemContainerGenerator generator, bool show = true) + private static void UpdateItems(ItemContainerGenerator generator, int itemsCount, bool show = true) { - var count = generator.Items.Count; if (show) { - for (int i = 0; i < count; i++) + for (int i = 0; i < itemsCount; i++) { var row = (DataGridRow)generator.ContainerFromIndex(i); if (row != null) @@ -258,7 +257,7 @@ namespace HandyControl.Controls } else { - for (int i = 0; i < count; i++) + for (int i = 0; i < itemsCount; i++) { var row = (DataGridRow)generator.ContainerFromIndex(i); if (row != null) diff --git a/HandyControl/Controls/Other/ColorPicker.cs b/HandyControl/Controls/Other/ColorPicker.cs index a41544cc..648dc3c6 100644 --- a/HandyControl/Controls/Other/ColorPicker.cs +++ b/HandyControl/Controls/Other/ColorPicker.cs @@ -422,13 +422,8 @@ namespace HandyControl.Controls /// private Button CreateColorButton(string colorStr) { - var colorObj = ColorConverter.ConvertFromString(colorStr); - var color = default(Color); - if (colorObj != null) - { - color = (Color)colorObj; - } - var brush = new SolidColorBrush(color); + var color = ColorConverter.ConvertFromString(colorStr) ?? default(Color); + var brush = new SolidColorBrush((Color)color); var button = new Button { diff --git a/HandyControl/Controls/Text/OutlineText.cs b/HandyControl/Controls/Text/OutlineText.cs index 1b73dd3f..9cd6c36f 100644 --- a/HandyControl/Controls/Text/OutlineText.cs +++ b/HandyControl/Controls/Text/OutlineText.cs @@ -153,7 +153,7 @@ namespace HandyControl.Controls return; } -#if net45 +#if net45 || net40 _formattedText = new FormattedText( Text, CultureInfo.CurrentUICulture, diff --git a/HandyControl/Controls/Window/WindowBorderless.cs b/HandyControl/Controls/Window/WindowBorderless.cs index 496a0db8..f806468e 100644 --- a/HandyControl/Controls/Window/WindowBorderless.cs +++ b/HandyControl/Controls/Window/WindowBorderless.cs @@ -4,9 +4,13 @@ using System.Windows.Controls; using System.Windows.Data; using System.Windows.Input; using System.Windows.Media; -using System.Windows.Shell; using HandyControl.Data; using HandyControl.Tools; +#if net40 +using Microsoft.Windows.Shell; +#else +using System.Windows.Shell; +#endif namespace HandyControl.Controls { diff --git a/HandyControl/HandyControl.csproj b/HandyControl/HandyControl.csproj index a1439ca2..eac0f8cb 100644 --- a/HandyControl/HandyControl.csproj +++ b/HandyControl/HandyControl.csproj @@ -8,11 +8,12 @@ library HandyControl HandyControl - 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 + + true @@ -23,6 +24,7 @@ prompt 4 v4.6.2 + netgt40 true @@ -33,6 +35,18 @@ prompt 4 v4.5 + netgt40 + + + true + full + false + bin\Debug\ + DEBUG;TRACE;net40 + prompt + 4 + v4.0 + net40 pdbonly @@ -43,7 +57,40 @@ 4 bin\Release\HandyControl.xml v4.6.2 + netgt40 + + pdbonly + true + bin\Release\ + TRACE;net45 + prompt + 4 + bin\Release\HandyControl.xml + v4.5 + netgt40 + + + pdbonly + true + bin\Release\ + TRACE;net40 + prompt + 4 + bin\Release\HandyControl.xml + v4.0 + net40 + + + + + + ..\packages\Microsoft.Windows.Shell.3.0.1.0\lib\net40\Microsoft.Windows.Shell.dll + + + + + @@ -589,14 +636,17 @@ Designer MSBuild:Compile - - Designer - MSBuild:Compile - Designer MSBuild:Compile + + MSBuild:Compile + True + True + Window.tt + Designer + Designer MSBuild:Compile @@ -634,10 +684,26 @@ TextTemplatingFileGenerator ResourceToken.cs + + + TextTemplatingFileGenerator + Window.xaml + + - + + + + + + + + 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 + + + \ No newline at end of file diff --git a/HandyControl/Themes/Styles/Base/ComboBoxBaseStyle.xaml b/HandyControl/Themes/Styles/Base/ComboBoxBaseStyle.xaml index ac64b1b1..afa7a89f 100644 --- a/HandyControl/Themes/Styles/Base/ComboBoxBaseStyle.xaml +++ b/HandyControl/Themes/Styles/Base/ComboBoxBaseStyle.xaml @@ -95,13 +95,13 @@ - + @@ -156,13 +156,13 @@ - + @@ -215,13 +215,13 @@ - + @@ -290,13 +290,13 @@ - + @@ -361,13 +361,13 @@ - + @@ -431,13 +431,13 @@ - + @@ -604,13 +604,13 @@ - + @@ -703,13 +703,13 @@ - + @@ -808,13 +808,13 @@ - + @@ -932,13 +932,13 @@ - + diff --git a/HandyControl/Themes/Styles/DataGrid.xaml b/HandyControl/Themes/Styles/DataGrid.xaml index 1e024b94..20e171a4 100644 --- a/HandyControl/Themes/Styles/DataGrid.xaml +++ b/HandyControl/Themes/Styles/DataGrid.xaml @@ -265,7 +265,7 @@ - + \ No newline at end of file diff --git a/HandyControl/Themes/Styles/ListView.xaml b/HandyControl/Themes/Styles/ListView.xaml index 8e6796a8..f5ec8276 100644 --- a/HandyControl/Themes/Styles/ListView.xaml +++ b/HandyControl/Themes/Styles/ListView.xaml @@ -163,7 +163,7 @@ - + \ No newline at end of file diff --git a/HandyControl/Themes/Styles/Style-Net40.xaml b/HandyControl/Themes/Styles/Style-Net40.xaml new file mode 100644 index 00000000..866dc60c --- /dev/null +++ b/HandyControl/Themes/Styles/Style-Net40.xaml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HandyControl/Themes/Styles/TreeView.xaml b/HandyControl/Themes/Styles/TreeView.xaml index 22d47426..2d4bacae 100644 --- a/HandyControl/Themes/Styles/TreeView.xaml +++ b/HandyControl/Themes/Styles/TreeView.xaml @@ -106,7 +106,7 @@ - + @@ -119,14 +119,14 @@ - + - + \ No newline at end of file diff --git a/HandyControl/Themes/Styles/Window-Net40.xaml b/HandyControl/Themes/Styles/Window-Net40.xaml new file mode 100644 index 00000000..7363b314 --- /dev/null +++ b/HandyControl/Themes/Styles/Window-Net40.xaml @@ -0,0 +1,251 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HandyControl/Themes/Styles/Window-net40.tt b/HandyControl/Themes/Styles/Window-net40.tt new file mode 100644 index 00000000..7363b314 --- /dev/null +++ b/HandyControl/Themes/Styles/Window-net40.tt @@ -0,0 +1,251 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HandyControl/Themes/Styles/Window-netgt40.tt b/HandyControl/Themes/Styles/Window-netgt40.tt new file mode 100644 index 00000000..e6fe8fdf --- /dev/null +++ b/HandyControl/Themes/Styles/Window-netgt40.tt @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HandyControl/Themes/Styles/Window.tt b/HandyControl/Themes/Styles/Window.tt new file mode 100644 index 00000000..933a7c3b --- /dev/null +++ b/HandyControl/Themes/Styles/Window.tt @@ -0,0 +1,3 @@ +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ output extension=".xaml" #> +<#@ include file="Window-$(netVersion).tt" #> \ No newline at end of file diff --git a/HandyControl/Themes/Styles/Window.xaml b/HandyControl/Themes/Styles/Window.xaml index 5c6cb6dc..e6fe8fdf 100644 --- a/HandyControl/Themes/Styles/Window.xaml +++ b/HandyControl/Themes/Styles/Window.xaml @@ -247,4 +247,4 @@ - + \ No newline at end of file diff --git a/HandyControl/packages.config b/HandyControl/packages.config new file mode 100644 index 00000000..9f4fefbc --- /dev/null +++ b/HandyControl/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/HandyControlDemo/HandyControlDemo.csproj b/HandyControlDemo/HandyControlDemo.csproj index 08afc754..3525060a 100644 --- a/HandyControlDemo/HandyControlDemo.csproj +++ b/HandyControlDemo/HandyControlDemo.csproj @@ -13,6 +13,8 @@ 4 true + + AnyCPU @@ -38,17 +40,6 @@ Resources\Img\icon.ico - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - v4.5 - ..\packages\CommonServiceLocator.2.0.2\lib\net45\CommonServiceLocator.dll @@ -716,4 +707,11 @@ + + + + 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 + + + \ No newline at end of file diff --git a/HandyControlDemo/Window/CommonWindow.xaml b/HandyControlDemo/Window/CommonWindow.xaml index 5dd9ebbe..77744b6c 100644 --- a/HandyControlDemo/Window/CommonWindow.xaml +++ b/HandyControlDemo/Window/CommonWindow.xaml @@ -12,6 +12,7 @@ Style="{StaticResource CustomWindowStyle}" Title="{x:Static langs:Lang.Title}" Height="450" - Width="800"> + Width="800" + Icon="/HandyControlDemo;component/Resources/Img/icon.ico"> \ No newline at end of file diff --git a/HandyControlDemo/packages.config b/HandyControlDemo/packages.config index d4e90a24..22441078 100644 --- a/HandyControlDemo/packages.config +++ b/HandyControlDemo/packages.config @@ -1,5 +1,6 @@  +