diff --git a/CHANGELIST.md b/CHANGELIST.md index b2fae764..ca108526 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -5,6 +5,7 @@ - Replace build script with Powershell - Fix Powershell build script - Fix cross-framework UI rendering +- Fix most .NET Framework 3.5 issues ### 3.0.1 (2023-11-30) diff --git a/MPF.UI.Core/MPF.UI.Core.csproj b/MPF.UI.Core/MPF.UI.Core.csproj index 85c38330..1edde7d9 100644 --- a/MPF.UI.Core/MPF.UI.Core.csproj +++ b/MPF.UI.Core/MPF.UI.Core.csproj @@ -2,7 +2,7 @@ - net40;net452;net462;net472;net48;netcoreapp3.1;net5.0-windows;net6.0-windows;net7.0-windows;net8.0-windows + net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0-windows;net6.0-windows;net7.0-windows;net8.0-windows win-x86;win-x64 false latest diff --git a/MPF/App.xaml b/MPF/App.xaml index 19bdf0a7..53133094 100644 --- a/MPF/App.xaml +++ b/MPF/App.xaml @@ -211,7 +211,7 @@ - + @@ -231,7 +231,7 @@ - + @@ -287,7 +287,8 @@ - + + @@ -329,67 +330,6 @@ - diff --git a/MPF/App.xaml.cs b/MPF/App.xaml.cs index 3b5a8966..c8324617 100644 --- a/MPF/App.xaml.cs +++ b/MPF/App.xaml.cs @@ -11,9 +11,12 @@ namespace MPF public partial class App : Application { -#if NET40_OR_GREATER || NETCOREAPP +#if NET35_OR_GREATER || NETCOREAPP - private const string _comboBoxTemplate = @" + /// + /// ComboBoxTemplate ControlTemplate XAML (.NET Framework 4.0 and above) + /// + private const string _comboBoxTemplateDefault = @" @@ -58,7 +61,51 @@ namespace MPF "; - private const string _comboBoxEditableTemplate = @" + /// + /// ComboBoxTemplate ControlTemplate XAML (.NET Framework 3.5) + /// + private const string _comboBoxTemplateNet35 = @" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + "; + + /// + /// ComboBoxEditableTemplate ControlTemplate XAML (.NET Framework 4.0 and above) + /// + private const string _comboBoxEditableTemplateDefault = @" @@ -110,36 +157,229 @@ namespace MPF "; + + /// + /// ComboBoxEditableTemplate ControlTemplate XAML (.NET Framework 3.5) + /// + private const string _comboBoxEditableTemplateNet35 = @" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + "; + + /// + /// CustomProgressBarStyle Style XAML (.NET Framework 4.0 and above) + /// + private const string _customProgressBarStyleDefault = @""; + + /// + /// CustomProgressBarStyle Style XAML (.NET Framework 3.5) + /// + private const string _customProgressBarStyleNet35 = @""; public App() { InitializeComponent(); CreateControlTemplate("ComboBoxTemplate"); CreateControlTemplate("ComboBoxEditableTemplate"); + CreateProgressBarStyle(); } + /// + /// Create an XAML parser context with the required namespaces + /// + private ParserContext CreateParserContext() + { + var context = new ParserContext(); + + context.XmlnsDictionary[""] = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"; + context.XmlnsDictionary["x"] = "http://schemas.microsoft.com/winfx/2006/xaml"; +#if NETFRAMEWORK + context.XmlnsDictionary["themes"] = "clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"; +#else + context.XmlnsDictionary["themes"] = "clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero2"; +#endif + context.XamlTypeMapper = new XamlTypeMapper([]); + + return context; + } + + /// + /// Create a named control template and add it to the current set of resources + /// private void CreateControlTemplate(string resourceName) { - var parserContext = new ParserContext(); - parserContext.XmlnsDictionary[""] = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"; - parserContext.XmlnsDictionary["x"] = "http://schemas.microsoft.com/winfx/2006/xaml"; -#if NETFRAMEWORK - parserContext.XmlnsDictionary["themes"] = "clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"; -#else - parserContext.XmlnsDictionary["themes"] = "clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero2"; -#endif - parserContext.XamlTypeMapper = new XamlTypeMapper([]); - + var parserContext = CreateParserContext(); var controlTemplate = resourceName switch { - "ComboBoxTemplate" => XamlReader.Parse(_comboBoxTemplate, parserContext) as ControlTemplate, - "ComboBoxEditableTemplate" => XamlReader.Parse(_comboBoxEditableTemplate, parserContext) as ControlTemplate, - _ => throw new ArgumentException(nameof(resourceName)), +#if NET35 + "ComboBoxTemplate" => XamlReader.Parse(_comboBoxTemplateNet35, parserContext) as ControlTemplate, + "ComboBoxEditableTemplate" => XamlReader.Parse(_comboBoxEditableTemplateNet35, parserContext) as ControlTemplate, +#else + "ComboBoxTemplate" => XamlReader.Parse(_comboBoxTemplateDefault, parserContext) as ControlTemplate, + "ComboBoxEditableTemplate" => XamlReader.Parse(_comboBoxEditableTemplateDefault, parserContext) as ControlTemplate, +#endif + _ => throw new ArgumentException($"'{resourceName}' is not a recognized control template", nameof(resourceName)), }; // Add the control template Resources[resourceName] = controlTemplate; } + + /// + /// Create the custom progress bar style and add it to the current set of resources + /// + private void CreateProgressBarStyle() + { + var parserContext = CreateParserContext(); +#if NET35 + var style = XamlReader.Parse(_customProgressBarStyleNet35, parserContext) as Style; +#else + var style = XamlReader.Parse(_customProgressBarStyleDefault, parserContext) as Style; #endif + + // Add the style + Resources["CustomProgressBarStyle"] = style; } +#endif + } } diff --git a/MPF/MPF.csproj b/MPF/MPF.csproj index 46241f8a..162e929a 100644 --- a/MPF/MPF.csproj +++ b/MPF/MPF.csproj @@ -2,7 +2,7 @@ - net40;net452;net462;net472;net48;netcoreapp3.1;net5.0-windows;net6.0-windows;net7.0-windows;net8.0-windows + net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0-windows;net6.0-windows;net7.0-windows;net8.0-windows win-x86;win-x64 WinExe Images\Icon.ico