mirror of
https://github.com/SabreTools/MPF.git
synced 2026-07-02 17:24:48 +00:00
Fix cross-framework UI rendering
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
- Add Disc ID and Key fields in info window
|
||||
- Replace build script with Powershell
|
||||
- Fix Powershell build script
|
||||
- Fix cross-framework UI rendering
|
||||
|
||||
### 3.0.1 (2023-11-30)
|
||||
|
||||
|
||||
60
MPF/App.xaml
60
MPF/App.xaml
@@ -1,7 +1,6 @@
|
||||
<Application
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
|
||||
xmlns:windows="clr-namespace:MPF.UI.Core.Windows;assembly=MPF.UI.Core"
|
||||
x:Class="MPF.App">
|
||||
<Application.MainWindow>
|
||||
@@ -205,26 +204,6 @@
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<ControlTemplate x:Key="ComboBoxTemplate" TargetType="{x:Type ComboBox}">
|
||||
<Grid x:Name="templateRoot" SnapsToDevicePixels="true">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Margin="1" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom" />
|
||||
<ToggleButton x:Name="toggleButton" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{DynamicResource ComboBoxToggleButton}"/>
|
||||
<ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" Content="{TemplateBinding SelectionBoxItem}" ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" IsHitTestVisible="false" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsGrouping" Value="true"/>
|
||||
<!--<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false"/>--> <!-- Not supported in .NET Framework 3.5 or 4.0 -->
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
|
||||
</MultiTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
<SolidColorBrush x:Key="TextBox.Static.Background" Color="#FFFFFFFF"/>
|
||||
<Style x:Key="ComboBoxEditableTextBox" TargetType="{x:Type TextBox}">
|
||||
<Setter Property="OverridesDefaultStyle" Value="true"/>
|
||||
@@ -232,7 +211,7 @@
|
||||
<Setter Property="MinWidth" Value="0"/>
|
||||
<Setter Property="MinHeight" Value="0"/>
|
||||
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
|
||||
<!--<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>--> <!-- Not supported in .NET Framework 3.5 -->
|
||||
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/> <!-- Not supported in .NET Framework 3.5 -->
|
||||
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
@@ -242,34 +221,6 @@
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<ControlTemplate x:Key="ComboBoxEditableTemplate" TargetType="{x:Type ComboBox}">
|
||||
<Grid x:Name="templateRoot" SnapsToDevicePixels="true">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom" />
|
||||
<ToggleButton x:Name="toggleButton" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{DynamicResource ComboBoxToggleButton}"/>
|
||||
<Border x:Name="border" Background="{DynamicResource TextBox.Static.Background}" Margin="{TemplateBinding BorderThickness}">
|
||||
<TextBox x:Name="PART_EditableTextBox" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" Margin="{TemplateBinding Padding}" Style="{DynamicResource ComboBoxEditableTextBox}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
|
||||
</Border>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsEnabled" Value="false">
|
||||
<Setter Property="Opacity" TargetName="border" Value="0.56"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsKeyboardFocusWithin" Value="true">
|
||||
<Setter Property="Foreground" Value="Black"/>
|
||||
</Trigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsGrouping" Value="true"/>
|
||||
<!--<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false"/>--> <!-- Not supported in .NET Framework 3.5 or 4.0 -->
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
|
||||
</MultiTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
<Style x:Key="CustomComboBoxStyle" TargetType="{x:Type ComboBox}">
|
||||
<Setter Property="FocusVisualStyle" Value="{DynamicResource FocusVisual}"/>
|
||||
<Setter Property="Background" Value="{DynamicResource ComboBox.Static.Background}"/>
|
||||
@@ -280,7 +231,7 @@
|
||||
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
|
||||
<Setter Property="Padding" Value="6,3,5,3"/>
|
||||
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
|
||||
<!--<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>--> <!-- Not supported in .NET Framework 3.5 -->
|
||||
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/> <!-- Not supported in .NET Framework 3.5 -->
|
||||
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
|
||||
<Setter Property="Template" Value="{DynamicResource ComboBoxTemplate}"/>
|
||||
<Style.Triggers>
|
||||
@@ -336,8 +287,7 @@
|
||||
<Popup x:Name="PART_Popup" AllowsTransparency="True" Focusable="False" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" Placement="Bottom">
|
||||
<Border x:Name="SubMenuBorder" BorderBrush="{DynamicResource MenuItem.SubMenu.Border}" BorderThickness="1" Background="{DynamicResource MenuItem.SubMenu.Background}" Padding="2">
|
||||
<ScrollViewer x:Name="SubMenuScrollViewer" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
|
||||
<!-- Grid RenderOptions.ClearTypeHint="Enabled">--> <!-- Not supported in .NET Framework 3.5 -->
|
||||
<Grid>
|
||||
<Grid RenderOptions.ClearTypeHint="Enabled"> <!-- Not supported in .NET Framework 3.5 -->
|
||||
<Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
|
||||
<Rectangle x:Name="OpaqueRect" Fill="{Binding Background, ElementName=SubMenuBorder}" Height="{Binding ActualHeight, ElementName=SubMenuBorder}" Width="{Binding ActualWidth, ElementName=SubMenuBorder}"/>
|
||||
</Canvas>
|
||||
@@ -389,7 +339,7 @@
|
||||
<ControlTemplate TargetType="{x:Type ProgressBar}">
|
||||
<Grid x:Name="TemplateRoot">
|
||||
<!-- Not supported in .NET Framework 3.5 -->
|
||||
<!--<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup x:Name="CommonStates">
|
||||
<VisualState x:Name="Determinate"/>
|
||||
<VisualState x:Name="Indeterminate">
|
||||
@@ -407,7 +357,7 @@
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>-->
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"/>
|
||||
<Rectangle x:Name="PART_Track"/>
|
||||
<Grid x:Name="PART_Indicator" ClipToBounds="true" HorizontalAlignment="Left">
|
||||
|
||||
283
MPF/App.xaml.cs
283
MPF/App.xaml.cs
@@ -1,11 +1,7 @@
|
||||
using System.Windows;
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
using Microsoft.Windows.Themes;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace MPF
|
||||
{
|
||||
@@ -16,173 +12,134 @@ namespace MPF
|
||||
{
|
||||
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
|
||||
private const string _comboBoxTemplate = @"<ControlTemplate x:Key=""ComboBoxTemplate"" TargetType=""{x:Type ComboBox}"">
|
||||
<Grid x:Name=""templateRoot"" SnapsToDevicePixels=""true"">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width=""*""/>
|
||||
<ColumnDefinition MinWidth=""{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"" Width=""0""/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Popup x:Name=""PART_Popup"" AllowsTransparency=""true"" Grid.ColumnSpan=""2"" IsOpen=""{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"" Margin=""1"" PopupAnimation=""{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}"" Placement=""Bottom"">
|
||||
<themes:SystemDropShadowChrome x:Name=""shadow"" Color=""Transparent"" MaxHeight=""{TemplateBinding MaxDropDownHeight}"" MinWidth=""{Binding ActualWidth, ElementName=templateRoot}"">
|
||||
<Border x:Name=""dropDownBorder"" BorderBrush=""{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}"" BorderThickness=""1"" Background=""{DynamicResource {x:Static SystemColors.WindowBrushKey}}"">
|
||||
<ScrollViewer x:Name=""DropDownScrollViewer"">
|
||||
<Grid x:Name=""grid"" RenderOptions.ClearTypeHint=""Enabled"">
|
||||
<Canvas x:Name=""canvas"" HorizontalAlignment=""Left"" Height=""0"" VerticalAlignment=""Top"" Width=""0"">
|
||||
<Rectangle x:Name=""opaqueRect"" Fill=""{Binding Background, ElementName=dropDownBorder}"" Height=""{Binding ActualHeight, ElementName=dropDownBorder}"" Width=""{Binding ActualWidth, ElementName=dropDownBorder}""/>
|
||||
</Canvas>
|
||||
<ItemsPresenter x:Name=""ItemsPresenter"" KeyboardNavigation.DirectionalNavigation=""Contained"" SnapsToDevicePixels=""{TemplateBinding SnapsToDevicePixels}""/>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
</themes:SystemDropShadowChrome>
|
||||
</Popup>
|
||||
<ToggleButton x:Name=""toggleButton"" BorderBrush=""{TemplateBinding BorderBrush}"" BorderThickness=""{TemplateBinding BorderThickness}"" Background=""{TemplateBinding Background}"" Grid.ColumnSpan=""2"" IsChecked=""{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"" Style=""{DynamicResource ComboBoxToggleButton}""/>
|
||||
<ContentPresenter x:Name=""contentPresenter"" ContentTemplate=""{TemplateBinding SelectionBoxItemTemplate}"" ContentTemplateSelector=""{TemplateBinding ItemTemplateSelector}"" Content=""{TemplateBinding SelectionBoxItem}"" ContentStringFormat=""{TemplateBinding SelectionBoxItemStringFormat}"" HorizontalAlignment=""{TemplateBinding HorizontalContentAlignment}"" IsHitTestVisible=""false"" Margin=""{TemplateBinding Padding}"" SnapsToDevicePixels=""{TemplateBinding SnapsToDevicePixels}"" VerticalAlignment=""{TemplateBinding VerticalContentAlignment}""/>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property=""HasDropShadow"" SourceName=""PART_Popup"" Value=""true"">
|
||||
<Setter Property=""Margin"" TargetName=""shadow"" Value=""0,0,5,5""/>
|
||||
<Setter Property=""Color"" TargetName=""shadow"" Value=""#71000000""/>
|
||||
</Trigger>
|
||||
<Trigger Property=""HasItems"" Value=""false"">
|
||||
<Setter Property=""Height"" TargetName=""dropDownBorder"" Value=""95""/>
|
||||
</Trigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property=""IsGrouping"" Value=""true""/>
|
||||
<Condition Property=""VirtualizingPanel.IsVirtualizingWhenGrouping"" Value=""false""/>
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property=""ScrollViewer.CanContentScroll"" Value=""false""/>
|
||||
</MultiTrigger>
|
||||
<Trigger Property=""ScrollViewer.CanContentScroll"" SourceName=""DropDownScrollViewer"" Value=""false"">
|
||||
<Setter Property=""Canvas.Top"" TargetName=""opaqueRect"" Value=""{Binding VerticalOffset, ElementName=DropDownScrollViewer}""/>
|
||||
<Setter Property=""Canvas.Left"" TargetName=""opaqueRect"" Value=""{Binding HorizontalOffset, ElementName=DropDownScrollViewer}""/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>";
|
||||
|
||||
private const string _comboBoxEditableTemplate = @"<ControlTemplate x:Key=""ComboBoxEditableTemplate"" TargetType=""{x:Type ComboBox}"">
|
||||
<Grid x:Name=""templateRoot"" SnapsToDevicePixels=""true"">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width=""*""/>
|
||||
<ColumnDefinition MinWidth=""{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"" Width=""0""/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Popup x:Name=""PART_Popup"" AllowsTransparency=""true"" Grid.ColumnSpan=""2"" IsOpen=""{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}"" PopupAnimation=""{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}"" Placement=""Bottom"">
|
||||
<themes:SystemDropShadowChrome x:Name=""shadow"" Color=""Transparent"" MaxHeight=""{TemplateBinding MaxDropDownHeight}"" MinWidth=""{Binding ActualWidth, ElementName=templateRoot}"">
|
||||
<Border x:Name=""dropDownBorder"" BorderBrush=""{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}"" BorderThickness=""1"" Background=""{DynamicResource {x:Static SystemColors.WindowBrushKey}}"">
|
||||
<ScrollViewer x:Name=""DropDownScrollViewer"">
|
||||
<Grid x:Name=""grid"" RenderOptions.ClearTypeHint=""Enabled"">
|
||||
<Canvas x:Name=""canvas"" HorizontalAlignment=""Left"" Height=""0"" VerticalAlignment=""Top"" Width=""0"">
|
||||
<Rectangle x:Name=""opaqueRect"" Fill=""{Binding Background, ElementName=dropDownBorder}"" Height=""{Binding ActualHeight, ElementName=dropDownBorder}"" Width=""{Binding ActualWidth, ElementName=dropDownBorder}""/>
|
||||
</Canvas>
|
||||
<ItemsPresenter x:Name=""ItemsPresenter"" KeyboardNavigation.DirectionalNavigation=""Contained"" SnapsToDevicePixels=""{TemplateBinding SnapsToDevicePixels}""/>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
</themes:SystemDropShadowChrome>
|
||||
</Popup>
|
||||
<ToggleButton x:Name=""toggleButton"" BorderBrush=""{TemplateBinding BorderBrush}"" BorderThickness=""{TemplateBinding BorderThickness}"" Background=""{TemplateBinding Background}"" Grid.ColumnSpan=""2"" IsChecked=""{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"" Style=""{DynamicResource ComboBoxToggleButton}""/>
|
||||
<Border x:Name=""border"" Background=""{DynamicResource TextBox.Static.Background}"" Margin=""{TemplateBinding BorderThickness}"">
|
||||
<TextBox x:Name=""PART_EditableTextBox"" HorizontalContentAlignment=""{TemplateBinding HorizontalContentAlignment}"" IsReadOnly=""{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}"" Margin=""{TemplateBinding Padding}"" Style=""{DynamicResource ComboBoxEditableTextBox}"" VerticalContentAlignment=""{TemplateBinding VerticalContentAlignment}""/>
|
||||
</Border>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property=""IsEnabled"" Value=""false"">
|
||||
<Setter Property=""Opacity"" TargetName=""border"" Value=""0.56""/>
|
||||
</Trigger>
|
||||
<Trigger Property=""IsKeyboardFocusWithin"" Value=""true"">
|
||||
<Setter Property=""Foreground"" Value=""Black""/>
|
||||
</Trigger>
|
||||
<Trigger Property=""HasDropShadow"" SourceName=""PART_Popup"" Value=""true"">
|
||||
<Setter Property=""Margin"" TargetName=""shadow"" Value=""0,0,5,5""/>
|
||||
<Setter Property=""Color"" TargetName=""shadow"" Value=""#71000000""/>
|
||||
</Trigger>
|
||||
<Trigger Property=""HasItems"" Value=""false"">
|
||||
<Setter Property=""Height"" TargetName=""dropDownBorder"" Value=""95""/>
|
||||
</Trigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property=""IsGrouping"" Value=""true""/>
|
||||
<Condition Property=""VirtualizingPanel.IsVirtualizingWhenGrouping"" Value=""false""/>
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property=""ScrollViewer.CanContentScroll"" Value=""false""/>
|
||||
</MultiTrigger>
|
||||
<Trigger Property=""ScrollViewer.CanContentScroll"" SourceName=""DropDownScrollViewer"" Value=""false"">
|
||||
<Setter Property=""Canvas.Top"" TargetName=""opaqueRect"" Value=""{Binding VerticalOffset, ElementName=DropDownScrollViewer}""/>
|
||||
<Setter Property=""Canvas.Left"" TargetName=""opaqueRect"" Value=""{Binding HorizontalOffset, ElementName=DropDownScrollViewer}""/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>";
|
||||
public App()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
AddDropShadowChrome("ComboBoxTemplate");
|
||||
AddDropShadowChrome("ComboBoxEditableTemplate");
|
||||
CreateControlTemplate("ComboBoxTemplate");
|
||||
CreateControlTemplate("ComboBoxEditableTemplate");
|
||||
}
|
||||
|
||||
private void AddDropShadowChrome(string resourceName)
|
||||
private void CreateControlTemplate(string resourceName)
|
||||
{
|
||||
// Get the template resource
|
||||
if (Resources[resourceName] is not ControlTemplate controlTemplate)
|
||||
return;
|
||||
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([]);
|
||||
|
||||
// Get the popup
|
||||
if (controlTemplate.Resources["PART_Popup"] is not Popup popup)
|
||||
return;
|
||||
|
||||
// Create the various nested items
|
||||
var chrome = new SystemDropShadowChrome
|
||||
var controlTemplate = resourceName switch
|
||||
{
|
||||
Name = "shadow",
|
||||
Color = Colors.Transparent,
|
||||
};
|
||||
var border = new Border
|
||||
{
|
||||
Name = "dropDownBorder",
|
||||
BorderThickness = new Thickness(1),
|
||||
};
|
||||
var scrollViewer = new ScrollViewer { Name = "DropDownScrollViewer" };
|
||||
var grid = new Grid { Name = "grid" };
|
||||
RenderOptions.SetClearTypeHint(grid, ClearTypeHint.Enabled);
|
||||
var canvas = new Canvas
|
||||
{
|
||||
Name = "canvas",
|
||||
HorizontalAlignment = HorizontalAlignment.Left,
|
||||
Height = 0,
|
||||
VerticalAlignment = VerticalAlignment.Top,
|
||||
Width = 0,
|
||||
};
|
||||
var rectangle = new Rectangle { Name = "opaqueRect" };
|
||||
var itemsPresenter = new ItemsPresenter { Name = "ItemsPresenter" };
|
||||
KeyboardNavigation.SetDirectionalNavigation(itemsPresenter, KeyboardNavigationMode.Contained);
|
||||
|
||||
// Set the bindings
|
||||
BindingOperations.SetBinding(chrome, SystemDropShadowChrome.MaxHeightProperty, new Binding
|
||||
{
|
||||
Source = new TemplateBindingExtension(ComboBox.MaxDropDownHeightProperty),
|
||||
});
|
||||
BindingOperations.SetBinding(chrome, SystemDropShadowChrome.MinWidthProperty, new Binding
|
||||
{
|
||||
Source = ComboBox.ActualWidthProperty,
|
||||
ElementName = "templateRoot",
|
||||
});
|
||||
|
||||
BindingOperations.SetBinding(border, Border.BorderBrushProperty, new Binding
|
||||
{
|
||||
Source = new DynamicResourceExtension(new StaticResourceExtension(SystemColors.WindowFrameBrushKey)),
|
||||
});
|
||||
BindingOperations.SetBinding(border, Border.BackgroundProperty, new Binding
|
||||
{
|
||||
Source = new DynamicResourceExtension(new StaticResourceExtension(SystemColors.WindowBrushKey)),
|
||||
});
|
||||
|
||||
BindingOperations.SetBinding(rectangle, Rectangle.FillProperty, new Binding
|
||||
{
|
||||
Source = Border.BackgroundProperty,
|
||||
ElementName = "dropDownBorder",
|
||||
});
|
||||
BindingOperations.SetBinding(rectangle, Rectangle.HeightProperty, new Binding
|
||||
{
|
||||
Source = Border.ActualHeightProperty,
|
||||
ElementName = "dropDownBorder",
|
||||
});
|
||||
BindingOperations.SetBinding(rectangle, Rectangle.WidthProperty, new Binding
|
||||
{
|
||||
Source = Border.ActualWidthProperty,
|
||||
ElementName = "dropDownBorder",
|
||||
});
|
||||
|
||||
BindingOperations.SetBinding(itemsPresenter, ItemsPresenter.SnapsToDevicePixelsProperty, new Binding
|
||||
{
|
||||
Source = new TemplateBindingExtension(ComboBox.SnapsToDevicePixelsProperty),
|
||||
});
|
||||
|
||||
// Build the item tree
|
||||
canvas.Children.Add(rectangle);
|
||||
grid.Children.Add(canvas);
|
||||
grid.Children.Add(itemsPresenter);
|
||||
scrollViewer.Content = grid;
|
||||
border.Child = scrollViewer;
|
||||
chrome.Child = border;
|
||||
|
||||
// Add the tree to the popup
|
||||
popup.Child = chrome;
|
||||
|
||||
// Get the triggers
|
||||
var triggers = controlTemplate.Triggers;
|
||||
if (triggers == null)
|
||||
return;
|
||||
|
||||
// Create the new triggers
|
||||
var hasDropShadow = new Trigger
|
||||
{
|
||||
Property = Popup.HasDropShadowProperty,
|
||||
SourceName = "PART_Popup",
|
||||
Value = "true",
|
||||
};
|
||||
var hasItems = new Trigger
|
||||
{
|
||||
Property = ComboBox.HasItemsProperty,
|
||||
Value = "false",
|
||||
};
|
||||
var canContentScroll = new Trigger
|
||||
{
|
||||
Property = ScrollViewer.CanContentScrollProperty,
|
||||
SourceName = "DropDownScrollViewer",
|
||||
Value = "false",
|
||||
"ComboBoxTemplate" => XamlReader.Parse(_comboBoxTemplate, parserContext) as ControlTemplate,
|
||||
"ComboBoxEditableTemplate" => XamlReader.Parse(_comboBoxEditableTemplate, parserContext) as ControlTemplate,
|
||||
_ => throw new ArgumentException(nameof(resourceName)),
|
||||
};
|
||||
|
||||
// Create and add the setters
|
||||
hasDropShadow.Setters.Add(new Setter
|
||||
{
|
||||
Property = SystemDropShadowChrome.MarginProperty,
|
||||
TargetName = "shadow",
|
||||
Value = "0,0,5,5",
|
||||
});
|
||||
hasDropShadow.Setters.Add(new Setter
|
||||
{
|
||||
Property = SystemDropShadowChrome.ColorProperty,
|
||||
TargetName = "shadow",
|
||||
Value = "#71000000",
|
||||
});
|
||||
|
||||
hasItems.Setters.Add(new Setter
|
||||
{
|
||||
Property = Border.HeightProperty,
|
||||
TargetName = "dropDownBorder",
|
||||
Value = "95",
|
||||
});
|
||||
|
||||
canContentScroll.Setters.Add(new Setter
|
||||
{
|
||||
Property = Canvas.TopProperty,
|
||||
TargetName = "opaqueRect",
|
||||
Value = new Binding
|
||||
{
|
||||
Source = ScrollViewer.VerticalOffsetProperty,
|
||||
ElementName = "DropDownScrollViewer",
|
||||
},
|
||||
});
|
||||
canContentScroll.Setters.Add(new Setter
|
||||
{
|
||||
Property = Canvas.LeftProperty,
|
||||
TargetName = "opaqueRect",
|
||||
Value = new Binding
|
||||
{
|
||||
Source = ScrollViewer.HorizontalOffsetProperty,
|
||||
ElementName = "DropDownScrollViewer",
|
||||
},
|
||||
});
|
||||
|
||||
// Add the new triggers
|
||||
triggers.Add(hasDropShadow);
|
||||
triggers.Add(hasItems);
|
||||
triggers.Add(canContentScroll);
|
||||
// Add the control template
|
||||
Resources[resourceName] = controlTemplate;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,14 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Special handling for Aero2 on non-Framework .NET -->
|
||||
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net4`))">
|
||||
<ReferenceWpfAeroTheme>true</ReferenceWpfAeroTheme>
|
||||
<ReferenceWpfAero2Theme>false</ReferenceWpfAero2Theme>
|
||||
<ReferenceWpfAeroLiteTheme>false</ReferenceWpfAeroLiteTheme>
|
||||
<ReferenceWpfClassicTheme>false</ReferenceWpfClassicTheme>
|
||||
<ReferenceWpfLunaTheme>false</ReferenceWpfLunaTheme>
|
||||
<ReferenceWpfRoyaleTheme>false</ReferenceWpfRoyaleTheme>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="$(TargetFramework.StartsWith(`netcoreapp`)) OR $(TargetFramework.StartsWith(`net5`)) OR $(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`))">
|
||||
<ReferenceWpfAeroTheme>false</ReferenceWpfAeroTheme>
|
||||
<ReferenceWpfAero2Theme>true</ReferenceWpfAero2Theme>
|
||||
@@ -66,36 +74,36 @@
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Special handling for Aero2 on non-Framework .NET -->
|
||||
<Target Name="SelectWpfThemeAssembly" AfterTargets="ResolveAssemblyReferences" Condition="'$(ReferenceWpfAeroTheme)' == 'true' Or
 '$(ReferenceWpfAero2Theme)' == 'true' Or
 '$(ReferenceWpfAeroLiteTheme)' == 'true' Or
 '$(ReferenceWpfClassicTheme)' == 'true' Or 
 '$(ReferenceWpfLunaTheme)' == 'true' Or
 '$(ReferenceWpfRoyaleTheme)' == 'true'">
|
||||
<ItemGroup Condition="$(TargetFramework.StartsWith(`netcoreapp`)) OR $(TargetFramework.StartsWith(`net5`)) OR $(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`))">
|
||||
<_WpfThemeAssemblies Include="@(ReferencePath)" Condition="'%(ReferencePath.NuGetPackageId)'=='Microsoft.WindowsDesktop.App.Ref' And 
 '%(ReferencePath.FileName)'=='PresentationFramework.Aero'">
|
||||
<Target Name="SelectWpfThemeAssembly" AfterTargets="ResolveAssemblyReferences" Condition="'$(ReferenceWpfAeroTheme)' == 'true' OR '$(ReferenceWpfAero2Theme)' == 'true' OR '$(ReferenceWpfAeroLiteTheme)' == 'true' OR '$(ReferenceWpfClassicTheme)' == 'true' OR '$(ReferenceWpfLunaTheme)' == 'true' OR '$(ReferenceWpfRoyaleTheme)' == 'true'">
|
||||
<ItemGroup>
|
||||
<_WpfThemeAssemblies Include="@(ReferencePath)" Condition="'%(ReferencePath.NuGetPackageId)'=='Microsoft.WindowsDesktop.App.Ref' AND '%(ReferencePath.FileName)'=='PresentationFramework.Aero'">
|
||||
<Aliases Condition="'$(WpfAeroThemeAliases)'!=''">$(WpfAeroThemeAliases)</Aliases>
|
||||
</_WpfThemeAssemblies>
|
||||
|
||||
<_WpfThemeAssemblies Include="@(ReferencePath)" Condition="'%(ReferencePath.NuGetPackageId)'=='Microsoft.WindowsDesktop.App.Ref' And 
 '%(ReferencePath.FileName)'=='PresentationFramework.Aero2'">
|
||||
<_WpfThemeAssemblies Include="@(ReferencePath)" Condition="'%(ReferencePath.NuGetPackageId)'=='Microsoft.WindowsDesktop.App.Ref' AND '%(ReferencePath.FileName)'=='PresentationFramework.Aero2'">
|
||||
<Aliases Condition="'$(WpfAero2ThemeAliases)'!=''">$(WpfAero2ThemeAliases)</Aliases>
|
||||
</_WpfThemeAssemblies>
|
||||
|
||||
<_WpfThemeAssemblies Include="@(ReferencePath)" Condition="'%(ReferencePath.NuGetPackageId)'=='Microsoft.WindowsDesktop.App.Ref' And 
 '%(ReferencePath.FileName)'=='PresentationFramework.AeroLite'">
|
||||
<_WpfThemeAssemblies Include="@(ReferencePath)" Condition="'%(ReferencePath.NuGetPackageId)'=='Microsoft.WindowsDesktop.App.Ref' AND '%(ReferencePath.FileName)'=='PresentationFramework.AeroLite'">
|
||||
<Aliases Condition="'$(WpfAeroLiteThemeAliases)'!=''">$(WpfAeroLiteThemeAliases)</Aliases>
|
||||
</_WpfThemeAssemblies>
|
||||
|
||||
<_WpfThemeAssemblies Include="@(ReferencePath)" Condition="'%(ReferencePath.NuGetPackageId)'=='Microsoft.WindowsDesktop.App.Ref' And 
 '%(ReferencePath.FileName)'=='PresentationFramework.Classic'">
|
||||
<_WpfThemeAssemblies Include="@(ReferencePath)" Condition="'%(ReferencePath.NuGetPackageId)'=='Microsoft.WindowsDesktop.App.Ref' AND '%(ReferencePath.FileName)'=='PresentationFramework.Classic'">
|
||||
<Aliases Condition="'$(WpfClassicThemeAliases)'!=''">$(WpfClassicThemeAliases)</Aliases>
|
||||
</_WpfThemeAssemblies>
|
||||
|
||||
<_WpfThemeAssemblies Include="@(ReferencePath)" Condition="'%(ReferencePath.NuGetPackageId)'=='Microsoft.WindowsDesktop.App.Ref' And 
 '%(ReferencePath.FileName)'=='PresentationFramework.Luna'">
|
||||
<_WpfThemeAssemblies Include="@(ReferencePath)" Condition="'%(ReferencePath.NuGetPackageId)'=='Microsoft.WindowsDesktop.App.Ref' AND '%(ReferencePath.FileName)'=='PresentationFramework.Luna'">
|
||||
<Aliases Condition="'$(WpfLunaThemeAliases)'!=''">$(WpfLunaThemeAliases)</Aliases>
|
||||
</_WpfThemeAssemblies>
|
||||
|
||||
<_WpfThemeAssemblies Include="@(ReferencePath)" Condition="'%(ReferencePath.NuGetPackageId)'=='Microsoft.WindowsDesktop.App.Ref' And 
 '%(ReferencePath.FileName)'=='PresentationFramework.Royale'">
|
||||
<_WpfThemeAssemblies Include="@(ReferencePath)" Condition="'%(ReferencePath.NuGetPackageId)'=='Microsoft.WindowsDesktop.App.Ref' AND '%(ReferencePath.FileName)'=='PresentationFramework.Royale'">
|
||||
<Aliases Condition="'$(WpfRoyaleThemeAliases)'!=''">$(WpfRoyaleThemeAliases)</Aliases>
|
||||
</_WpfThemeAssemblies>
|
||||
|
||||
<ReferencePath Remove="@(_WpfThemeAssemblies)" />
|
||||
<ReferencePath Include="@(_WpfThemeAssemblies)" Condition="('%(_WpfThemeAssemblies.FileName)'=='PresentationFramework.Aero' And '$(ReferenceWpfAeroTheme)'=='true') Or 
 ('%(_WpfThemeAssemblies.FileName)'=='PresentationFramework.Aero2' And '$(ReferenceWpfAero2Theme)'=='true') Or 
 ('%(_WpfThemeAssemblies.FileName)'=='PresentationFramework.AeroLite' And '$(ReferenceWpfAeroLiteTheme)'=='true') Or 
 ('%(_WpfThemeAssemblies.FileName)'=='PresentationFramework.Classic' And '$(ReferenceWpfClassicTheme)'=='true') Or 
 ('%(_WpfThemeAssemblies.FileName)'=='PresentationFramework.Luna' And '$(ReferenceWpfLunaTheme)'=='true') Or
 ('%(_WpfThemeAssemblies.FileName)'=='PresentationFramework.Royale' And '$(ReferenceWpfRoyaleTheme)'=='true')" />
|
||||
<ReferencePath Include="@(_WpfThemeAssemblies)" Condition="('%(_WpfThemeAssemblies.FileName)'=='PresentationFramework.Aero' AND'$(ReferenceWpfAeroTheme)'=='true') OR ('%(_WpfThemeAssemblies.FileName)'=='PresentationFramework.Aero2' AND '$(ReferenceWpfAero2Theme)'=='true') OR ('%(_WpfThemeAssemblies.FileName)'=='PresentationFramework.AeroLite' AND '$(ReferenceWpfAeroLiteTheme)'=='true') OR ('%(_WpfThemeAssemblies.FileName)'=='PresentationFramework.Classic' AND '$(ReferenceWpfClassicTheme)'=='true') OR ('%(_WpfThemeAssemblies.FileName)'=='PresentationFramework.Luna' AND '$(ReferenceWpfLunaTheme)'=='true') OR ('%(_WpfThemeAssemblies.FileName)'=='PresentationFramework.Royale' AND '$(ReferenceWpfRoyaleTheme)'=='true')" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
|
||||
</Project>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user