diff --git a/CHANGELIST.md b/CHANGELIST.md index ca108526..5fdcbfa1 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -6,6 +6,7 @@ - Fix Powershell build script - Fix cross-framework UI rendering - Fix most .NET Framework 3.5 issues +- Fix cross-framework UI styles ### 3.0.1 (2023-11-30) diff --git a/MPF/App.xaml b/MPF/App.xaml index 53133094..cda9095d 100644 --- a/MPF/App.xaml +++ b/MPF/App.xaml @@ -205,43 +205,6 @@ - - diff --git a/MPF/App.xaml.cs b/MPF/App.xaml.cs index c8324617..3c5f340a 100644 --- a/MPF/App.xaml.cs +++ b/MPF/App.xaml.cs @@ -13,6 +13,8 @@ namespace MPF #if NET35_OR_GREATER || NETCOREAPP + #region ControlTemplates + /// /// ComboBoxTemplate ControlTemplate XAML (.NET Framework 4.0 and above) /// @@ -207,6 +209,98 @@ namespace MPF "; + #endregion + + #region Styles + + /// + /// ComboBoxEditableTextBox Style XAML (.NET Framework 4.0 and above) + /// + private const string _comboBoxEditableTextBoxStyleDefault = @""; + + /// + /// ComboBoxEditableTextBox Style XAML (.NET Framework 3.5) + /// + private const string _comboBoxEditableTextBoxStyleNet35 = @""; + + /// + /// CustomComboBoxStyle Style XAML (.NET Framework 4.0 and above) + /// + private const string _customComboBoxStyleDefault = @""; + + /// + /// CustomComboBoxStyle Style XAML (.NET Framework 3.5) + /// + private const string _customComboBoxStyleNet35 = @""; + /// /// CustomProgressBarStyle Style XAML (.NET Framework 4.0 and above) /// @@ -315,13 +409,20 @@ namespace MPF "; + + #endregion public App() { InitializeComponent(); + // Create control templates CreateControlTemplate("ComboBoxTemplate"); CreateControlTemplate("ComboBoxEditableTemplate"); - CreateProgressBarStyle(); + + // Create styles + CreateStyle("ComboBoxEditableTextBox"); + CreateStyle("CustomComboBoxStyle"); + CreateStyle("CustomProgressBarStyle"); } /// @@ -366,19 +467,27 @@ namespace MPF } /// - /// Create the custom progress bar style and add it to the current set of resources + /// Create a named style and add it to the current set of resources /// - private void CreateProgressBarStyle() + private void CreateStyle(string resourceName) { var parserContext = CreateParserContext(); + var style = resourceName switch + { #if NET35 - var style = XamlReader.Parse(_customProgressBarStyleNet35, parserContext) as Style; + "ComboBoxEditableTextBox" => XamlReader.Parse(_comboBoxEditableTextBoxStyleNet35, parserContext) as Style, + "CustomComboBoxStyle" => XamlReader.Parse(_customComboBoxStyleNet35, parserContext) as Style, + "CustomProgressBarStyle" => XamlReader.Parse(_customProgressBarStyleNet35, parserContext) as Style, #else - var style = XamlReader.Parse(_customProgressBarStyleDefault, parserContext) as Style; + "ComboBoxEditableTextBox" => XamlReader.Parse(_comboBoxEditableTextBoxStyleDefault, parserContext) as Style, + "CustomComboBoxStyle" => XamlReader.Parse(_customComboBoxStyleDefault, parserContext) as Style, + "CustomProgressBarStyle" => XamlReader.Parse(_customProgressBarStyleDefault, parserContext) as Style, #endif + _ => throw new ArgumentException($"'{resourceName}' is not a recognized style", nameof(resourceName)), + }; // Add the style - Resources["CustomProgressBarStyle"] = style; + Resources[resourceName] = style; } #endif }