diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/PresentationBuildTasks.csproj b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/PresentationBuildTasks.csproj
index c8583201b02..bfdd1716c05 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/PresentationBuildTasks.csproj
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/PresentationBuildTasks.csproj
@@ -73,9 +73,6 @@
Shared\MS\Internal\ReflectionUtils.cs
-
- Shared\MS\Internal\SecurityHelper.cs
-
Shared\MS\Internal\TokenizerHelper.cs
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj b/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj
index f7b4b4c031e..481b9c49b48 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj
@@ -714,6 +714,7 @@
+
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/MouseActionConverter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/MouseActionConverter.cs
index fe804828b30..c69a7b1226e 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/MouseActionConverter.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/MouseActionConverter.cs
@@ -7,12 +7,12 @@
namespace System.Windows.Input
{
///
- /// Converter class for converting between a and .
+ /// Converter class for converting between a and .
///
public class MouseActionConverter : TypeConverter
{
///
- /// Used to check whether we can convert a into a .
+ /// Used to check whether we can convert a into a .
///
///ITypeDescriptorContext
///type to convert from
@@ -24,11 +24,11 @@ public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceT
}
///
- /// Used to check whether we can convert specified value to .
+ /// Used to check whether we can convert specified value to .
///
/// ITypeDescriptorContext
/// Type to convert to
- /// if conversion to is possible, otherwise.
+ /// if conversion to is possible, otherwise.
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
// We can convert to an InstanceDescriptor or to a string
@@ -36,20 +36,20 @@ public override bool CanConvertTo(ITypeDescriptorContext context, Type destinati
return false;
// When invoked by the serialization engine we can convert to string only for known type
- if (context is null || context.Instance is null)
+ if (context?.Instance is not MouseAction mouseAction)
return false;
// Make sure the value falls within defined set
- return IsDefinedMouseAction((MouseAction)context.Instance);
+ return IsDefinedMouseAction(mouseAction);
}
///
- /// Converts of type to its represensation.
+ /// Converts of type to its representation.
///
/// Parser Context
/// Culture Info
/// MouseAction String
- /// A representing the specified by .
+ /// A representing the specified by .
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object source)
{
if (source is not string mouseAction)
@@ -72,21 +72,20 @@ _ when mouseActionToken.Equals("MiddleDoubleClick", StringComparison.OrdinalIgno
}
///
- /// Converts a of to its represensation.
+ /// Converts a of to its representation.
///
/// Serialization Context
/// Culture Info
/// MouseAction value
/// Type to Convert
- /// A representing the specified by .
+ /// A representing the specified by .
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
ArgumentNullException.ThrowIfNull(destinationType);
- if (value is null || destinationType != typeof(string))
+ if (value is not MouseAction mouseAction || destinationType != typeof(string))
throw GetConvertToException(value, destinationType);
- MouseAction mouseAction = (MouseAction)value;
return mouseAction switch
{
MouseAction.None => string.Empty,
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/DoubleCollection.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/DoubleCollection.cs
new file mode 100644
index 00000000000..f4a965d79e8
--- /dev/null
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/DoubleCollection.cs
@@ -0,0 +1,23 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using MS.Utility;
+
+namespace System.Windows.Media;
+
+public sealed partial class DoubleCollection
+{
+ ///
+ /// Initializes a new instance using a . Elements are copied.
+ ///
+ ///
+ internal DoubleCollection(params ReadOnlySpan values)
+ {
+ _collection = new FrugalStructList(values.Length);
+
+ foreach (double item in values)
+ {
+ _collection.Add(item);
+ }
+ }
+}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/NativeMethodsMilCoreApi.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/NativeMethodsMilCoreApi.cs
deleted file mode 100644
index f801b630ebd..00000000000
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/NativeMethodsMilCoreApi.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-//------------------------------------------------------------------------------
-//
-//
-// ABOUT THIS FILE:
-// -- This file contains native methods which are deemed NOT SAFE for partial trust callers
-// -- These methods DO NOT have the SuppressUnmanagedCodeSecurity attribute on them
-// which means stalk walks for unmanaged code will bubble all the way up the stack
-// -- Put methods in here which are not needed in partial trust scenarios and/or when a stack walk is
-// appropriate
-// -- If you have questions about how to use this file, email avsee
-//-----------------------------------------------------------------------------
-
-namespace MS.Win32
-{
- using Accessibility;
- using System.Runtime.InteropServices;
- using System;
- using System.Collections;
- using System.Diagnostics;
- using System.IO;
- using System.Text;
- using Microsoft.Win32;
- using System.Windows.Media.Composition;
-
- internal static partial class NativeMethods
- {
- }
-}
-
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentViewerHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentViewerHelper.cs
index 61d87234bbe..b63f9a0a865 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentViewerHelper.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentViewerHelper.cs
@@ -271,13 +271,9 @@ private static CultureInfo GetDocumentCultureInfo(ITextContainer textContainer)
/// FindToolBar instance.
internal static void ShowFindUnsuccessfulMessage(FindToolBar findToolBar)
{
- string messageString;
-
// No, we did not find anything. Alert the user.
- messageString = findToolBar.SearchUp ?
- SR.DocumentViewerSearchUpCompleteLabel :
- SR.DocumentViewerSearchDownCompleteLabel;
- messageString = String.Format(System.Globalization.CultureInfo.CurrentCulture, messageString, findToolBar.SearchText);
+ string messageString = findToolBar.SearchUp ? SR.DocumentViewerSearchUpCompleteLabel : SR.DocumentViewerSearchDownCompleteLabel;
+ messageString = string.Format(CultureInfo.CurrentCulture, messageString, findToolBar.SearchText);
HwndSource hwndSource = PresentationSource.CriticalFromVisual(findToolBar) as HwndSource;
IntPtr hwnd = (hwndSource != null) ? hwndSource.Handle : IntPtr.Zero;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGrid.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGrid.cs
index ecf1a7c7bd4..64a4b8d5745 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGrid.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGrid.cs
@@ -8464,9 +8464,13 @@ private object InvalidateCellsPanelHorizontalOffset(object args)
IProvideDataGridColumn cell = GetAnyCellOrColumnHeader();
if (cell != null)
{
- CellsPanelHorizontalOffset = DataGridHelper.GetParentCellsPanelHorizontalOffset(cell);
+ // Due to layout rounding, computation of the offset may return a negative value while computing the difference between controls,
+ // however since this offset is used also for Button's Width servicing the DataGrid.SelectAllCommand in all standard styles,
+ // we cannot accept this. Even if we could, the DataGrid[CellsPanel] layout logic depends on this offset being 0 or greater.
+ // See https://github.com/dotnet/wpf/pull/9983 for more information regarding this.
+ CellsPanelHorizontalOffset = Math.Max(0d, DataGridHelper.GetParentCellsPanelHorizontalOffset(cell));
}
- else if (!Double.IsNaN(RowHeaderWidth))
+ else if (!double.IsNaN(RowHeaderWidth))
{
CellsPanelHorizontalOffset = RowHeaderWidth;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GridViewColumnHeader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GridViewColumnHeader.cs
index 58490630aa8..2ee7b861f65 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GridViewColumnHeader.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GridViewColumnHeader.cs
@@ -856,7 +856,7 @@ private bool HandleIsMouseOverChanged()
(_headerGripper == null || !_headerGripper.IsMouseOver))
{
// Hovering over the button will click in the OnHover click mode
- SetValue(IsPressedPropertyKey, BooleanBoxes.Box(true));
+ SetValue(IsPressedPropertyKey, BooleanBoxes.TrueBox);
OnClick();
}
else
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Interop/HwndHost.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Interop/HwndHost.cs
index 892eee06208..4c540de4dcb 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Interop/HwndHost.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Interop/HwndHost.cs
@@ -85,23 +85,17 @@ public event HwndSourceHook MessageHook
{
add
{
-
- if(_hooks == null)
- {
- _hooks = new ArrayList(8);
- }
+ _hooks ??= new List(8);
_hooks.Add(value);
}
-
remove
{
-
- if(_hooks != null)
+ if (_hooks is not null)
{
_hooks.Remove(value);
- if(_hooks.Count == 0)
+ if (_hooks.Count == 0)
{
_hooks = null;
}
@@ -1101,22 +1095,19 @@ private object AsyncDestroyWindow(object arg)
private IntPtr SubclassWndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
- IntPtr result = IntPtr.Zero ;
+ // Call the virtual first
+ IntPtr result = WndProc(hwnd, msg, wParam, lParam, ref handled);
- // Call the virtual first.
- result = WndProc(hwnd, msg, wParam, lParam, ref handled);
+ if (_hooks is null || handled)
+ return result;
- // Call the handlers for the MessageHook event.
- if(!handled && _hooks != null)
+ // Call the handlers for the MessageHook event
+ for (int i = 0, nCount = _hooks.Count; i < nCount; i++)
{
- for(int i = 0, nCount = _hooks.Count; i < nCount; i++)
- {
- result = ((HwndSourceHook)_hooks[i])(hwnd, msg, wParam, lParam, ref handled);
- if(handled)
- {
- break;
- }
- }
+ result = _hooks[i].Invoke(hwnd, msg, wParam, lParam, ref handled);
+
+ if (handled)
+ break;
}
return result;
@@ -1132,7 +1123,7 @@ private IntPtr SubclassWndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lPara
private HandleRef _hwnd;
- private ArrayList _hooks;
+ private List _hooks;
private Size _desiredSize;
///
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XmlnsCache.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XmlnsCache.cs
index 69c5550f182..5cc34e38085 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XmlnsCache.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XmlnsCache.cs
@@ -14,9 +14,7 @@
using System.Linq;
using System.Reflection;
using MS.Utility;
-#if PBTCOMPILER
-using MS.Internal.PresentationBuildTasks;
-#else
+#if !PBTCOMPILER
using MS.Internal.PresentationFramework;
using MS.Internal.Utility; // AssemblyCacheEnum
#endif
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Style.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Style.cs
index eb193cd8f14..df8b15b2d11 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Style.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Style.cs
@@ -954,7 +954,7 @@ private static bool IsEqual(object a, object b)
// Original Style data (not including based-on data)
// Synchronized (write locks, lock-free reads): Covered by Style instance lock
- /* property */ internal FrugalStructList PropertyValues = new FrugalStructList();
+ internal FrugalStructList PropertyValues = new();
// Properties driven on the container (by the Style) that should be
// invalidated when the style gets applied/unapplied. These properties
diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/ReachFramework.csproj b/src/Microsoft.DotNet.Wpf/src/ReachFramework/ReachFramework.csproj
index 1f0244eb90b..8565543b468 100644
--- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/ReachFramework.csproj
+++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/ReachFramework.csproj
@@ -51,7 +51,6 @@
-
diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/SecurityHelper.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/SecurityHelper.cs
index 253a139e39e..a089867572c 100644
--- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/SecurityHelper.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/SecurityHelper.cs
@@ -7,29 +7,18 @@
*
\***************************************************************************/
-using System.Security;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Microsoft.Win32;
-#if !PBTCOMPILER
-using MS.Win32;
-using System.IO.Packaging;
-#endif
-
#if PRESENTATION_CORE
using MS.Internal.AppModel;
+using System.Security;
+using MS.Win32;
#endif
#if PRESENTATIONFRAMEWORK_ONLY
-using System.Diagnostics;
using System.Windows;
-using MS.Internal.Utility; // BindUriHelper
-using MS.Internal.AppModel;
-#endif
-
-#if REACHFRAMEWORK
-using MS.Internal.Utility;
#endif
#if WINDOWS_BASE
// This existed originally to allow FontCache service to
@@ -50,10 +39,6 @@ namespace MS.Internal.WindowsBase
namespace MS.Internal // Promote the one from PresentationCore as the default to use.
#elif PRESENTATIONFRAMEWORK
namespace MS.Internal.PresentationFramework
-#elif PBTCOMPILER
-namespace MS.Internal.PresentationBuildTasks
-#elif REACHFRAMEWORK
-namespace MS.Internal.ReachFramework
#elif DRT
namespace MS.Internal.Drt
#else
diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/ContainerUtilities.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/ContainerUtilities.cs
index 574195cd92f..39f7618caf9 100644
--- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/ContainerUtilities.cs
+++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/ContainerUtilities.cs
@@ -11,11 +11,7 @@
using System.Text; // for StringBuilder
using System.Diagnostics; // for Debug.Assert
-
-#if PBTCOMPILER
-using MS.Utility; // For SR.cs
-using MS.Internal.PresentationBuildTasks;
-#else
+#if !PBTCOMPILER
using System.Windows;
using MS.Internal.WindowsBase;
#endif
diff --git a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/System/Windows/Input/MouseActionConverter.Tests.cs b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/System/Windows/Input/MouseActionConverter.Tests.cs
index 5fa2efad7d3..b189f9ffb92 100644
--- a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/System/Windows/Input/MouseActionConverter.Tests.cs
+++ b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/System/Windows/Input/MouseActionConverter.Tests.cs
@@ -23,7 +23,7 @@ public void CanConvertFrom_ReturnsExpected(bool expected, Type sourceType)
}
[Theory]
- [MemberData(nameof(CanConvertTo_Data))]
+ [MemberData(nameof(CanConvertTo_ReturnsExpected_Data))]
public void CanConvertTo_ReturnsExpected(bool expected, bool passContext, object? value, Type? destinationType)
{
MouseActionConverter converter = new();
@@ -32,7 +32,7 @@ public void CanConvertTo_ReturnsExpected(bool expected, bool passContext, object
Assert.Equal(expected, converter.CanConvertTo(passContext ? context : null, destinationType));
}
- public static IEnumerable