diff --git a/eng/WpfArcadeSdk/tools/Wpf.Cpp.targets b/eng/WpfArcadeSdk/tools/Wpf.Cpp.targets
index f1a7de9a9bb..ad973b35172 100644
--- a/eng/WpfArcadeSdk/tools/Wpf.Cpp.targets
+++ b/eng/WpfArcadeSdk/tools/Wpf.Cpp.targets
@@ -353,6 +353,16 @@ using namespace System::Runtime::Versioning;
+
+
+
+
+
+
GetUnmanagedStream();
+ _fontSourcePointer = _fontSourceStream->PositionPointer - _fontSourceStream->Position;
try
{
_lastWriteTime = fontSource->GetLastWriteTimeUtc().ToFileTimeUtc();
- }
+ }
catch(System::ArgumentOutOfRangeException^) //The resulting file time would represent a date and time before 12:00 midnight January 1, 1601 C.E. UTC.
{
_lastWriteTime = -1;
- }
-
- // Create lock to control access to font source stream.
- _fontSourceStreamLock = gcnew Object();
+ }
}
FontFileStream::~FontFileStream()
@@ -61,31 +59,9 @@ namespace MS { namespace Internal { namespace Text { namespace TextInterface
return E_INVALIDARG;
}
- int fragmentSizeInt = (int)fragmentSize;
- array^ buffer = gcnew array(fragmentSizeInt);
-
- // DWrite may call this method from multiple threads. We need to ensure thread safety by making Seek and Read atomic.
- System::Threading::Monitor::Enter(_fontSourceStreamLock);
- try
- {
- _fontSourceStream->Seek(fileOffset, //long
- System::IO::SeekOrigin::Begin);
-
- _fontSourceStream->Read(buffer, //byte[]
- 0, //int
- fragmentSizeInt //int
- );
- }
- finally
- {
- System::Threading::Monitor::Exit(_fontSourceStreamLock);
- }
-
- GCHandle gcHandle = GCHandle::Alloc(buffer, GCHandleType::Pinned);
-
- *fragmentStart = (byte*)(gcHandle.AddrOfPinnedObject().ToPointer());
-
- *fragmentContext = GCHandle::ToIntPtr(gcHandle).ToPointer();
+ // Return a pointer to the font data that is already loaded in memory (because the font source resource is mmapped into the process' address space).
+ *fragmentStart = _fontSourcePointer + fileOffset;
+ *fragmentContext = nullptr;
}
catch(System::Exception^ exception)
{
@@ -102,11 +78,6 @@ namespace MS { namespace Internal { namespace Text { namespace TextInterface
void* fragmentContext
)
{
- if (fragmentContext != NULL)
- {
- GCHandle gcHandle = GCHandle::FromIntPtr(IntPtr(fragmentContext));
- gcHandle.Free();
- }
}
[ComVisible(true)]
diff --git a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/FontFileStream.h b/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/FontFileStream.h
index fa1f3a50c24..49cf479b0b4 100644
--- a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/FontFileStream.h
+++ b/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/FontFileStream.h
@@ -20,9 +20,9 @@ namespace MS { namespace Internal { namespace Text { namespace TextInterface
private ref class FontFileStream : public IDWriteFontFileStreamMirror
{
private:
- Stream^ _fontSourceStream;
+ UnmanagedMemoryStream^ _fontSourceStream;
+ Byte* _fontSourcePointer;
INT64 _lastWriteTime;
- Object^ _fontSourceStreamLock;
public:
diff --git a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/DirectWriteForwarder.vcxproj b/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/DirectWriteForwarder.vcxproj
index 5155bf4aa99..d73c1b95835 100644
--- a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/DirectWriteForwarder.vcxproj
+++ b/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/DirectWriteForwarder.vcxproj
@@ -31,6 +31,11 @@
.NETCoreApp
v6.0
Unknown
+
+ true
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/SynchronizedInputHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/SynchronizedInputHelper.cs
index 3d020a8e1cc..28cfd0a05ef 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/SynchronizedInputHelper.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/SynchronizedInputHelper.cs
@@ -297,21 +297,18 @@ internal static RoutedEvent[] MapInputTypeToRoutedEvents(SynchronizedInputType i
internal static void RaiseAutomationEvents()
{
- if (InputElement.IsUIElement(InputManager.ListeningElement))
+ if (InputManager.ListeningElement is UIElement e)
{
- UIElement e = (UIElement)InputManager.ListeningElement;
//Raise InputDiscarded automation event
SynchronizedInputHelper.RaiseAutomationEvent(e.GetAutomationPeer());
}
- else if (InputElement.IsContentElement(InputManager.ListeningElement))
+ else if (InputManager.ListeningElement is ContentElement ce)
{
- ContentElement ce = (ContentElement)InputManager.ListeningElement;
//Raise InputDiscarded automation event
SynchronizedInputHelper.RaiseAutomationEvent(ce.GetAutomationPeer());
}
- else if (InputElement.IsUIElement3D(InputManager.ListeningElement))
+ else if (InputManager.ListeningElement is UIElement3D e3D)
{
- UIElement3D e3D = (UIElement3D)InputManager.ListeningElement;
//Raise InputDiscarded automation event
SynchronizedInputHelper.RaiseAutomationEvent(e3D.GetAutomationPeer());
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/UIElementHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/UIElementHelper.cs
index 4496a6a014f..b699b840377 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/UIElementHelper.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/UIElementHelper.cs
@@ -141,7 +141,7 @@ internal static DependencyObject GetUIParent(DependencyObject child, bool contin
[FriendAccessAllowed]
internal static bool IsUIElementOrUIElement3D(DependencyObject o)
{
- return (o is UIElement || o is UIElement3D);
+ return (o is UIElement or UIElement3D);
}
[FriendAccessAllowed]
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/CommandBinding.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/CommandBinding.cs
index 0890cda1424..02acc51b56a 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/CommandBinding.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/CommandBinding.cs
@@ -7,6 +7,7 @@
using System;
using System.ComponentModel;
+using System.Diagnostics;
using System.Windows;
using System.Windows.Markup;
using MS.Internal;
@@ -60,18 +61,13 @@ public CommandBinding(ICommand command, ExecutedRoutedEventHandler executed)
/// Handler associated with determining if the command can execute.
public CommandBinding(ICommand command, ExecutedRoutedEventHandler executed, CanExecuteRoutedEventHandler canExecute)
{
- if (command == null)
- {
- throw new ArgumentNullException("command");
- }
+ _command = command ?? throw new ArgumentNullException(nameof(command));
- _command = command;
-
- if (executed != null)
+ if (executed is not null)
{
Executed += executed;
}
- if (canExecute != null)
+ if (canExecute is not null)
{
CanExecute += canExecute;
}
@@ -87,20 +83,8 @@ public CommandBinding(ICommand command, ExecutedRoutedEventHandler executed, Can
[Localizability(LocalizationCategory.NeverLocalize)] // cannot be localized
public ICommand Command
{
- get
- {
- return _command;
- }
-
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException("value");
- }
-
- _command = value;
- }
+ get => _command;
+ set => _command = value ?? throw new ArgumentNullException(nameof(value));
}
#endregion
@@ -138,49 +122,46 @@ public ICommand Command
/// Event arguments.
internal void OnCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
- if (!e.Handled)
+ if (e.Handled) return;
+ if (e.RoutedEvent == CommandManager.CanExecuteEvent)
{
- if (e.RoutedEvent == CommandManager.CanExecuteEvent)
+ if (CanExecute is null)
{
- if (CanExecute != null)
- {
- CanExecute(sender, e);
- if (e.CanExecute)
- {
- e.Handled = true;
- }
- }
- else if (!e.CanExecute)
- {
- // If there is an Executed handler, then the command can be executed.
- if (Executed != null)
- {
- e.CanExecute = true;
- e.Handled = true;
- }
- }
+ if (e.CanExecute) return;
+ // If there is an Executed handler, then the command can be executed.
+ if (Executed is null) return;
+ e.CanExecute = true;
+ e.Handled = true;
}
- else // e.RoutedEvent == CommandManager.PreviewCanExecuteEvent
+ else
{
- if (PreviewCanExecute != null)
+ CanExecute(sender, e);
+ if (e.CanExecute)
{
- PreviewCanExecute(sender, e);
- if (e.CanExecute)
- {
- e.Handled = true;
- }
+ e.Handled = true;
}
}
}
+ else // e.RoutedEvent == CommandManager.PreviewCanExecuteEvent
+ {
+ if (PreviewCanExecute is null) return;
+ PreviewCanExecute(sender, e);
+ if (e.CanExecute)
+ {
+ e.Handled = true;
+ }
+ }
}
private bool CheckCanExecute(object sender, ExecutedRoutedEventArgs e)
{
- CanExecuteRoutedEventArgs canExecuteArgs = new CanExecuteRoutedEventArgs(e.Command, e.Parameter);
- canExecuteArgs.RoutedEvent = CommandManager.CanExecuteEvent;
+ CanExecuteRoutedEventArgs canExecuteArgs = new(e.Command, e.Parameter)
+ {
+ RoutedEvent = CommandManager.CanExecuteEvent,
+ // Since we don't actually raise this event, we have to explicitly set the source.
+ Source = e.OriginalSource
+ };
- // Since we don't actually raise this event, we have to explicitly set the source.
- canExecuteArgs.Source = e.OriginalSource;
canExecuteArgs.OverrideSource(e.Source);
OnCanExecute(sender, canExecuteArgs);
@@ -195,30 +176,22 @@ private bool CheckCanExecute(object sender, ExecutedRoutedEventArgs e)
/// Event arguments.
internal void OnExecuted(object sender, ExecutedRoutedEventArgs e)
{
- if (!e.Handled)
+ if (e.Handled) return;
+ if (e.RoutedEvent == CommandManager.ExecutedEvent)
{
- if (e.RoutedEvent == CommandManager.ExecutedEvent)
- {
- if (Executed != null)
- {
- if (CheckCanExecute(sender, e))
- {
- Executed(sender, e);
- e.Handled = true;
- }
- }
- }
- else // e.RoutedEvent == CommandManager.PreviewExecutedEvent
- {
- if (PreviewExecuted != null)
- {
- if (CheckCanExecute(sender, e))
- {
- PreviewExecuted(sender, e);
- e.Handled = true;
- }
- }
- }
+ if (Executed is null) return;
+ if (!CheckCanExecute(sender, e)) return;
+ Debug.Assert(Executed != null, nameof(Executed) + " != null");
+ Executed(sender, e);
+ e.Handled = true;
+ }
+ else // e.RoutedEvent == CommandManager.PreviewExecutedEvent
+ {
+ if (PreviewExecuted is null) return;
+ if (!CheckCanExecute(sender, e)) return;
+ Debug.Assert(PreviewExecuted != null, nameof(PreviewExecuted) + " != null");
+ PreviewExecuted(sender, e);
+ e.Handled = true;
}
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/CommandBindingCollection.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/CommandBindingCollection.cs
index 98725d64267..8adf9e4d232 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/CommandBindingCollection.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/CommandBindingCollection.cs
@@ -52,9 +52,9 @@ public CommandBindingCollection()
/// CommandBinding array
public CommandBindingCollection(IList commandBindings)
{
- if (commandBindings != null && commandBindings.Count > 0)
+ if (commandBindings is { Count: > 0 })
{
- AddRange(commandBindings as ICollection);
+ AddRange(commandBindings);
}
}
@@ -76,12 +76,9 @@ public CommandBindingCollection(IList commandBindings)
///
/// commandbinding array to copy into
/// start index in current list to copy
- void ICollection.CopyTo(System.Array array, int index)
+ void ICollection.CopyTo(System.Array array, int index)
{
- if (_innerCBList != null)
- {
- ((ICollection)_innerCBList).CopyTo(array, index);
- }
+ ((ICollection)_innerCBList)?.CopyTo(array, index);
}
#endregion Implementation of ICollection
@@ -92,7 +89,7 @@ void ICollection.CopyTo(System.Array array, int index)
/// true - if found, false - otherwise
bool IList.Contains(object key)
{
- return this.Contains(key as CommandBinding) ;
+ return Contains(key as CommandBinding) ;
}
///
@@ -102,8 +99,7 @@ bool IList.Contains(object key)
///
int IList.IndexOf(object value)
{
- CommandBinding commandBinding = value as CommandBinding;
- return ((commandBinding != null) ? this.IndexOf(commandBinding) : -1);
+ return ((value is CommandBinding commandBinding) ? IndexOf(commandBinding) : -1);
}
///
@@ -113,7 +109,7 @@ int IList.IndexOf(object value)
/// item to insert
void IList.Insert(int index, object value)
{
- this.Insert(index, value as CommandBinding);
+ Insert(index, value as CommandBinding);
}
///
@@ -122,7 +118,7 @@ void IList.Insert(int index, object value)
/// CommandBinding object to add
int IList.Add(object commandBinding)
{
- return this.Add(commandBinding as CommandBinding);
+ return Add(commandBinding as CommandBinding);
}
///
@@ -131,7 +127,7 @@ int IList.Add(object commandBinding)
/// CommandBinding object to remove
void IList.Remove(object commandBinding)
{
- this.Remove(commandBinding as CommandBinding);
+ Remove(commandBinding as CommandBinding);
}
///
@@ -145,8 +141,7 @@ object IList.this[int index]
}
set
{
- CommandBinding commandBinding = value as CommandBinding;
- if (commandBinding == null)
+ if (value is not CommandBinding commandBinding)
throw new NotSupportedException(SR.Get(SRID.CollectionOnlyAcceptsCommandBindings));
this[index] = commandBinding;
@@ -160,7 +155,7 @@ public CommandBinding this[int index]
{
get
{
- return (_innerCBList != null ? _innerCBList[index] : null);
+ return (_innerCBList?[index]);
}
set
{
@@ -179,8 +174,7 @@ public int Add(CommandBinding commandBinding)
{
if (commandBinding != null)
{
- if (_innerCBList == null)
- _innerCBList = new System.Collections.Generic.List(1);
+ _innerCBList ??= new Collections.Generic.List(1);
_innerCBList.Add(commandBinding);
return 0; // ICollection.Add no longer returns the indice
@@ -200,27 +194,23 @@ public int Add(CommandBinding commandBinding)
public void AddRange(ICollection collection)
{
if (collection==null)
- throw new ArgumentNullException("collection");
-
- if (collection.Count > 0)
- {
- if (_innerCBList == null)
- _innerCBList = new System.Collections.Generic.List(collection.Count);
+ throw new ArgumentNullException(nameof(collection));
+
+ if (collection.Count <= 0) return;
+ _innerCBList ??= new System.Collections.Generic.List(collection.Count);
- IEnumerator collectionEnum = collection.GetEnumerator();
- while(collectionEnum.MoveNext())
+ IEnumerator collectionEnum = collection.GetEnumerator();
+ while(collectionEnum.MoveNext())
+ {
+ if (collectionEnum.Current is CommandBinding cmdBinding)
{
- CommandBinding cmdBinding = collectionEnum.Current as CommandBinding;
- if (cmdBinding != null)
- {
- _innerCBList.Add(cmdBinding);
- }
- else
- {
- throw new NotSupportedException(SR.Get(SRID.CollectionOnlyAcceptsCommandBindings));
- }
- }
- }
+ _innerCBList.Add(cmdBinding);
+ }
+ else
+ {
+ throw new NotSupportedException(SR.Get(SRID.CollectionOnlyAcceptsCommandBindings));
+ }
+ }
}
///
@@ -232,8 +222,7 @@ public void Insert(int index, CommandBinding commandBinding)
{
if (commandBinding != null)
{
- if (_innerCBList != null)
- _innerCBList.Insert(index, commandBinding);
+ _innerCBList?.Insert(index, commandBinding);
}
else
{
@@ -257,8 +246,7 @@ public void Remove(CommandBinding commandBinding)
/// index at which the item needs to be removed
public void RemoveAt(int index)
{
- if (_innerCBList != null)
- _innerCBList.RemoveAt(index);
+ _innerCBList?.RemoveAt(index);
}
///
@@ -276,11 +264,7 @@ public bool IsSynchronized
{
get
{
- if (_innerCBList != null)
- {
- return ((IList)_innerCBList).IsSynchronized;
- }
- return false;
+ return _innerCBList is not null && ((IList)_innerCBList).IsSynchronized;
}
}
@@ -310,7 +294,7 @@ public int Count
{
get
{
- return (_innerCBList != null ? _innerCBList.Count : 0);
+ return _innerCBList?.Count ?? 0;
}
}
@@ -319,11 +303,9 @@ public int Count
///
public void Clear()
{
- if (_innerCBList != null)
- {
- _innerCBList.Clear();
- _innerCBList = null;
- }
+ if (_innerCBList is null) return;
+ _innerCBList.Clear();
+ _innerCBList = null;
}
///
@@ -333,7 +315,7 @@ public void Clear()
///
public int IndexOf(CommandBinding value)
{
- return ((_innerCBList != null) ? _innerCBList.IndexOf(value) : -1);
+ return _innerCBList?.IndexOf(value) ?? -1;
}
///
@@ -355,10 +337,9 @@ public bool Contains(CommandBinding commandBinding)
///
/// type-safe (CommandBinding) array
/// start index in current list to copy
- public void CopyTo(CommandBinding[] commandBindings, int index)
+ public void CopyTo(CommandBinding[] commandBindings, int index)
{
- if (_innerCBList != null)
- _innerCBList.CopyTo(commandBindings, index);
+ _innerCBList?.CopyTo(commandBindings, index);
}
#region Implementation of Enumerable
@@ -385,17 +366,11 @@ internal ICommand FindMatch(object targetElement, InputEventArgs inputEventArgs)
for (int i = 0; i < Count; i++)
{
CommandBinding commandBinding = this[i];
- RoutedCommand routedCommand = commandBinding.Command as RoutedCommand;
- if (routedCommand != null)
+ if (commandBinding.Command is not RoutedCommand routedCommand) continue;
+ InputGestureCollection inputGestures = routedCommand.InputGesturesInternal;
+ if (inputGestures?.FindMatch(targetElement, inputEventArgs) != null)
{
- InputGestureCollection inputGestures = routedCommand.InputGesturesInternal;
- if (inputGestures != null)
- {
- if (inputGestures.FindMatch(targetElement, inputEventArgs) != null)
- {
- return routedCommand;
- }
- }
+ return routedCommand;
}
}
@@ -423,7 +398,7 @@ internal CommandBinding FindMatch(ICommand command, ref int index)
//
//------------------------------------------------------
#region Private Fields
- private System.Collections.Generic.List _innerCBList;
+ private Collections.Generic.List _innerCBList;
#endregion Private Fields
}
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/CommandManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/CommandManager.cs
index 26f934c821f..3a0454e3212 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/CommandManager.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/CommandManager.cs
@@ -352,9 +352,9 @@ internal static void TranslateInput(IInputElement targetElement, InputEventArgs
// Determine UIElement/ContentElement/Neither type
DependencyObject targetElementAsDO = targetElement as DependencyObject;
- bool isUIElement = InputElement.IsUIElement(targetElementAsDO);
- bool isContentElement = !isUIElement && InputElement.IsContentElement(targetElementAsDO);
- bool isUIElement3D = !isUIElement && !isContentElement && InputElement.IsUIElement3D(targetElementAsDO);
+ bool isUIElement = targetElementAsDO is UIElement;
+ bool isContentElement = !isUIElement && targetElementAsDO is ContentElement;
+ bool isUIElement3D = !isUIElement && !isContentElement && targetElementAsDO is UIElement3D;
// Step 1: Check local input bindings
InputBindingCollection localInputBindings = null;
@@ -370,6 +370,7 @@ internal static void TranslateInput(IInputElement targetElement, InputEventArgs
{
localInputBindings = ((UIElement3D)targetElement).InputBindingsInternal;
}
+
if (localInputBindings != null)
{
InputBinding inputBinding = localInputBindings.FindMatch(targetElement, inputEventArgs);
@@ -423,6 +424,7 @@ internal static void TranslateInput(IInputElement targetElement, InputEventArgs
{
localCommandBindings = ((UIElement3D)targetElement).CommandBindingsInternal;
}
+
if (localCommandBindings != null)
{
command = localCommandBindings.FindMatch(targetElement, inputEventArgs);
@@ -599,64 +601,56 @@ internal static void OnCommandDevice(object sender, CommandDeviceEventArgs e)
private static void FindCommandBinding(object sender, RoutedEventArgs e, ICommand command, bool execute)
{
// Check local command bindings
- CommandBindingCollection commandBindings = null;
- DependencyObject senderAsDO = sender as DependencyObject;
- if (InputElement.IsUIElement(senderAsDO))
- {
- commandBindings = ((UIElement)senderAsDO).CommandBindingsInternal;
- }
- else if (InputElement.IsContentElement(senderAsDO))
+ CommandBindingCollection commandBindings = sender switch
{
- commandBindings = ((ContentElement)senderAsDO).CommandBindingsInternal;
- }
- else if (InputElement.IsUIElement3D(senderAsDO))
- {
- commandBindings = ((UIElement3D)senderAsDO).CommandBindingsInternal;
- }
- if (commandBindings != null)
+ UIElement uiElement => uiElement.CommandBindingsInternal,
+ ContentElement contentElement => contentElement.CommandBindingsInternal,
+ UIElement3D uiElement3d => uiElement3d.CommandBindingsInternal,
+ _ => default
+ };
+ if (commandBindings is not null)
{
FindCommandBinding(commandBindings, sender, e, command, execute);
}
+ Type senderType = sender.GetType();
+
// If no command binding is found, check class command bindings
// First find the relevant command bindings, under the lock.
// Most of the time there are no such bindings; most of the rest of
// the time there is only one. Lazy-allocate with this in mind.
- Tuple tuple = null; // zero or one binding
- List> list = null; // more than one
-
+ ValueTuple? tuple = default; // zero or one binding
+ List> list = default; // more than one
+
lock (_classCommandBindings.SyncRoot)
{
// Check from the current type to all the base types
- Type classType = sender.GetType();
- while (classType != null)
+ Type classType = senderType;
+ while (classType is not null)
{
- CommandBindingCollection classCommandBindings = _classCommandBindings[classType] as CommandBindingCollection;
- if (classCommandBindings != null)
+ if (_classCommandBindings[classType] is CommandBindingCollection classCommandBindings)
{
int index = 0;
while (true)
{
CommandBinding commandBinding = classCommandBindings.FindMatch(command, ref index);
- if (commandBinding != null)
+ if (commandBinding is null)
{
- if (tuple == null)
- {
- tuple = new Tuple(classType, commandBinding);
- }
- else
- {
- if (list == null)
- {
- list = new List>();
- list.Add(tuple);
- }
- list.Add(new Tuple(classType, commandBinding));
- }
+ break;
+ }
+
+ if (tuple is null)
+ {
+ tuple = ValueTuple.Create(classType, commandBinding);
}
else
{
- break;
+ list ??= new List>(8)
+ {
+ // We know that tuple cannot be null here
+ tuple.Value
+ };
+ list.Add(new ValueTuple(classType, commandBinding));
}
}
}
@@ -666,37 +660,35 @@ private static void FindCommandBinding(object sender, RoutedEventArgs e, IComman
// execute the bindings. This can call into user code, so it must
// be done outside the lock to avoid deadlock.
- if (list != null)
+ if (list is not null)
{
// more than one binding
- ExecutedRoutedEventArgs exArgs = execute ? (ExecutedRoutedEventArgs)e : null;
- CanExecuteRoutedEventArgs canExArgs = execute ? null : (CanExecuteRoutedEventArgs)e;
- for (int i=0; i info;
- if (InputElement.IsUIElement(o))
+ if (o is UIElement uie)
{
- UIElement uie = o as UIElement;
uie.AddHandler(SourceChangedEvent, handler);
info = uie.EventHandlersStore[SourceChangedEvent];
if (1 == info.Count)
@@ -156,9 +155,8 @@ public static void AddSourceChangedHandler(IInputElement element, SourceChangedE
AddElementToWatchList(uie);
}
}
- else if (InputElement.IsUIElement3D(o))
+ else if (o is UIElement3D uie3D)
{
- UIElement3D uie3D = o as UIElement3D;
uie3D.AddHandler(SourceChangedEvent, handler);
info = uie3D.EventHandlersStore[SourceChangedEvent];
if (1 == info.Count)
@@ -167,13 +165,18 @@ public static void AddSourceChangedHandler(IInputElement element, SourceChangedE
AddElementToWatchList(uie3D);
}
}
- else
+ else if (o is ContentElement ce)
{
- ContentElement ce = o as ContentElement;
ce.AddHandler(SourceChangedEvent, handler);
info = ce.EventHandlersStore[SourceChangedEvent];
if (1 == info.Count)
+ {
AddElementToWatchList(ce);
+ }
+ }
+ else
+ {
+ throw new InvalidOperationException(SR.Get(SRID.Invalid_IInputElement, o.GetType()));
}
}
}
@@ -211,9 +214,8 @@ public static void RemoveSourceChangedHandler(IInputElement e, SourceChangedEven
EventHandlersStore store;
// Either UIElement or ContentElement.
- if (InputElement.IsUIElement(o))
+ if (o is UIElement uie)
{
- UIElement uie = o as UIElement;
uie.RemoveHandler(SourceChangedEvent, handler);
store = uie.EventHandlersStore;
if (store != null)
@@ -226,9 +228,8 @@ public static void RemoveSourceChangedHandler(IInputElement e, SourceChangedEven
RemoveElementFromWatchList(uie);
}
}
- else if (InputElement.IsUIElement3D(o))
+ else if (o is UIElement3D uie3D)
{
- UIElement3D uie3D = o as UIElement3D;
uie3D.RemoveHandler(SourceChangedEvent, handler);
store = uie3D.EventHandlersStore;
if (store != null)
@@ -241,9 +242,8 @@ public static void RemoveSourceChangedHandler(IInputElement e, SourceChangedEven
RemoveElementFromWatchList(uie3D);
}
}
- else
+ else if (o is ContentElement ce)
{
- ContentElement ce = o as ContentElement;
ce.RemoveHandler(SourceChangedEvent, handler);
store = ce.EventHandlersStore;
if (store != null)
@@ -255,6 +255,10 @@ public static void RemoveSourceChangedHandler(IInputElement e, SourceChangedEven
RemoveElementFromWatchList(ce);
}
}
+ else
+ {
+ throw new InvalidOperationException(SR.Get(SRID.Invalid_IInputElement, o.GetType()));
+ }
}
}
@@ -548,7 +552,7 @@ protected void ClearContentRenderedListeners()
/// Event Args.
internal static void OnVisualAncestorChanged(DependencyObject uie, AncestorChangedEventArgs e)
{
- Debug.Assert(InputElement.IsUIElement3D(uie) || InputElement.IsUIElement(uie));
+ Debug.Assert(uie is UIElement3D or UIElement);
if (true == (bool)uie.GetValue(GetsSourceChangedEventProperty))
{
@@ -740,17 +744,21 @@ private static bool UpdateSourceOfElement(DependencyObject doTarget,
SourceChangedEventArgs args = new SourceChangedEventArgs(cachedSource, realSource);
args.RoutedEvent=SourceChangedEvent;
- if (InputElement.IsUIElement(doTarget))
+ if (doTarget is UIElement uiElement)
{
- ((UIElement)doTarget).RaiseEvent(args);
+ uiElement.RaiseEvent(args);
}
- else if (InputElement.IsContentElement(doTarget))
+ else if (doTarget is ContentElement contentElement)
+ {
+ contentElement.RaiseEvent(args);
+ }
+ else if (doTarget is UIElement3D uiElement3D)
{
- ((ContentElement)doTarget).RaiseEvent(args);
+ uiElement3D.RaiseEvent(args);
}
else
{
- ((UIElement3D)doTarget).RaiseEvent(args);
+ throw new InvalidOperationException(SR.Get(SRID.Invalid_IInputElement, doTarget.GetType()));
}
calledOut = true;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement.cs
index 14e0a26b6d4..49d9a88f4f3 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement.cs
@@ -1443,7 +1443,7 @@ protected internal override void OnVisualParentChanged(DependencyObject oldParen
{
DependencyObject parent = _parent;
- if (!InputElement.IsUIElement(parent) && !InputElement.IsUIElement3D(parent))
+ if (parent is not UIElement and not UIElement3D)
{
Visual parentAsVisual = parent as Visual;
@@ -1490,7 +1490,7 @@ protected internal override void OnVisualParentChanged(DependencyObject oldParen
{
DependencyObject parent = oldParent;
- if (!InputElement.IsUIElement(parent) && !InputElement.IsUIElement3D(parent))
+ if (parent is not UIElement and not UIElement3D)
{
// We are being unplugged from a non-UIElement visual. This
// means that our parent didn't play by the same rules we
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement3D.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement3D.cs
index f6761dfe11d..33efb11b54f 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement3D.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement3D.cs
@@ -148,7 +148,7 @@ protected internal override void OnVisualParentChanged(DependencyObject oldParen
{
DependencyObject parent = InternalVisualParent;
- if (!InputElement.IsUIElement(parent) && !InputElement.IsUIElement3D(parent))
+ if (parent is not UIElement and not UIElement3D)
{
Visual parentAsVisual = parent as Visual;
@@ -192,7 +192,7 @@ protected internal override void OnVisualParentChanged(DependencyObject oldParen
{
DependencyObject parent = oldParent;
- if (!InputElement.IsUIElement(parent) && !InputElement.IsUIElement3D(parent))
+ if (parent is not UIElement and not UIElement3D)
{
// We are being unplugged from a non-UIElement visual. This
// means that our parent didn't play by the same rules we
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/PathNode.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/PathNode.cs
index 1ff7bf6c7b6..7f5dd44dec9 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/PathNode.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/PathNode.cs
@@ -229,7 +229,7 @@ internal static DependencyObject GetParent(DependencyObject node)
Debug.Assert(node != null, "node can not be null");
DependencyObject current = node;
- DependencyObject parent = null;
+ DependencyObject parent;
while (true)
{
@@ -255,16 +255,15 @@ internal static DependencyObject GetParent(DependencyObject node)
}
// Check if located a parent, if so, check if it's the correct type
- if ((parent == null) ||
- FrameworkElement.DType.IsInstanceOfType(parent) ||
- FrameworkContentElement.DType.IsInstanceOfType(parent))
+ if (parent is null
+ or FrameworkElement
+ or FrameworkContentElement)
{
break;
}
// Parent found but not of correct type, continue
current = parent;
- parent = null;
}
return parent;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/FrameworkObject.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/FrameworkObject.cs
index 4234020478c..bde4847e41a 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/FrameworkObject.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/FrameworkObject.cs
@@ -57,21 +57,8 @@ internal FrameworkObject(DependencyObject d)
// [code should be identical to Reset(d)]
_do = d;
- if (FrameworkElement.DType.IsInstanceOfType(d))
- {
- _fe = (FrameworkElement)d;
- _fce = null;
- }
- else if (FrameworkContentElement.DType.IsInstanceOfType(d))
- {
- _fe = null;
- _fce = (FrameworkContentElement)d;
- }
- else
- {
- _fe = null;
- _fce = null;
- }
+ _fe = d as FrameworkElement;
+ _fce = d as FrameworkContentElement;
}
internal FrameworkObject(DependencyObject d, bool throwIfNeither)
@@ -99,21 +86,8 @@ internal void Reset(DependencyObject d)
{
_do = d;
- if (FrameworkElement.DType.IsInstanceOfType(d))
- {
- _fe = (FrameworkElement)d;
- _fce = null;
- }
- else if (FrameworkContentElement.DType.IsInstanceOfType(d))
- {
- _fe = null;
- _fce = (FrameworkContentElement)d;
- }
- else
- {
- _fe = null;
- _fce = null;
- }
+ _fe = d as FrameworkElement;
+ _fce = d as FrameworkContentElement;
}
#endregion Constructors
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Helper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Helper.cs
index a45d7b9df42..197122f118c 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Helper.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Helper.cs
@@ -286,15 +286,15 @@ internal static void DowncastToFEorFCE(DependencyObject d,
out FrameworkElement fe, out FrameworkContentElement fce,
bool throwIfNeither)
{
- if (FrameworkElement.DType.IsInstanceOfType(d))
+ if (d is FrameworkElement frameworkElement)
{
- fe = (FrameworkElement)d;
+ fe = frameworkElement;
fce = null;
}
- else if (FrameworkContentElement.DType.IsInstanceOfType(d))
+ else if (d is FrameworkContentElement frameworkContentElement)
{
fe = null;
- fce = (FrameworkContentElement)d;
+ fce = frameworkContentElement;
}
else if (throwIfNeither)
{
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/ClipboardProcessor.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/ClipboardProcessor.cs
index 40aecf7e5e8..e7160832144 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/ClipboardProcessor.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/ClipboardProcessor.cs
@@ -213,9 +213,9 @@ internal bool PasteData(IDataObject dataObject, ref StrokeCollection newStrokes,
// If the Xaml data has been set in an InkCanvas, the top element will be a container InkCanvas.
// In this case, the new elements will be the children of the container.
// Otherwise, the new elements will be whatever data from the data object.
- if (elements.Count == 1 && ClipboardProcessor.InkCanvasDType.IsInstanceOfType(elements[0]))
+ if (elements.Count == 1 && elements[0] is InkCanvas inkCanvas)
{
- TearDownInkCanvasContainer((InkCanvas)( elements[0] ), ref newStrokes, ref newElements);
+ TearDownInkCanvasContainer(inkCanvas, ref newStrokes, ref newElements);
}
else
{
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PrePostDescendentsWalker.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PrePostDescendentsWalker.cs
index e40e1032aa9..4a4f884039d 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PrePostDescendentsWalker.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PrePostDescendentsWalker.cs
@@ -72,7 +72,7 @@ public override void StartWalk(DependencyObject startNode, bool skipStartNode)
{
// This type checking is done in DescendentsWalker. Doing it here
// keeps us consistent.
- if (FrameworkElement.DType.IsInstanceOfType(startNode) || FrameworkContentElement.DType.IsInstanceOfType(startNode))
+ if (startNode is FrameworkElement or FrameworkContentElement)
{
_postCallback(startNode, this.Data, _priority == TreeWalkPriority.VisualTree);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/MenuItemAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/MenuItemAutomationPeer.cs
index 0cf50a7b53d..10bce1bcb12 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/MenuItemAutomationPeer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/MenuItemAutomationPeer.cs
@@ -316,6 +316,16 @@ internal void RaiseExpandCollapseAutomationEvent(bool oldValue, bool newValue)
newValue ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed);
}
+ [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
+ internal void RaiseToggleStatePropertyChangedEvent(bool oldValue, bool newValue)
+ {
+ RaisePropertyChangedEvent(TogglePatternIdentifiers.ToggleStateProperty,
+ oldValue ? ConvertToToggleState(oldValue) : ConvertToToggleState(newValue),
+ newValue ? ConvertToToggleState(oldValue) : ConvertToToggleState(newValue));
+ }
+
+ private static ToggleState ConvertToToggleState(bool value) => value ? ToggleState.On : ToggleState.Off;
+
// Return the base without the AccessKey character
///
override protected string GetNameCore()
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/BroadcastEventHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/BroadcastEventHelper.cs
index 056f12d17e6..ace65f98990 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/BroadcastEventHelper.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/BroadcastEventHelper.cs
@@ -292,12 +292,10 @@ private static bool OnBroadcastCallback(DependencyObject d, BroadcastEventData d
DependencyObject root = data.Root;
RoutedEvent routedEvent = data.RoutedEvent;
List eventRoute = data.EventRoute;
-
- if (FrameworkElement.DType.IsInstanceOfType(d))
- {
- // If this is a FrameworkElement
- FrameworkElement fe = (FrameworkElement)d;
+ // If this is a FrameworkElement
+ if (d is FrameworkElement fe)
+ {
if (fe != root && routedEvent == FrameworkElement.LoadedEvent && fe.UnloadedPending != null)
{
// If there is a pending Unloaded event wait till we've broadcast
@@ -422,22 +420,22 @@ private static bool OnBroadcastCallback(DependencyObject d, BroadcastEventData d
private static bool SubtreeHasLoadedChangeHandlerHelper(DependencyObject d)
{
- if (FrameworkElement.DType.IsInstanceOfType(d))
+ if (d is FrameworkElement fe)
{
- return ((FrameworkElement)d).SubtreeHasLoadedChangeHandler;
+ return fe.SubtreeHasLoadedChangeHandler;
}
- else if (FrameworkContentElement.DType.IsInstanceOfType(d))
+ else if (d is FrameworkContentElement fce)
{
- return ((FrameworkContentElement)d).SubtreeHasLoadedChangeHandler;
+ return fce.SubtreeHasLoadedChangeHandler;
}
return false;
}
private static void FireLoadedOnDescendentsHelper(DependencyObject d)
{
- if (FrameworkElement.DType.IsInstanceOfType(d))
+ if (d is FrameworkElement fe)
{
- ((FrameworkElement)d).FireLoadedOnDescendentsInternal();
+ fe.FireLoadedOnDescendentsInternal();
}
else
{
@@ -447,9 +445,9 @@ private static void FireLoadedOnDescendentsHelper(DependencyObject d)
private static void FireUnloadedOnDescendentsHelper(DependencyObject d)
{
- if (FrameworkElement.DType.IsInstanceOfType(d))
+ if (d is FrameworkElement fe)
{
- ((FrameworkElement)d).FireUnloadedOnDescendentsInternal();
+ fe.FireUnloadedOnDescendentsInternal();
}
else
{
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MenuItem.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MenuItem.cs
index 18b01f43097..5891c18c4fc 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MenuItem.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MenuItem.cs
@@ -946,7 +946,10 @@ private static void OnIsCheckedChanged(DependencyObject d, DependencyPropertyCha
{
MenuItem menuItem = (MenuItem) d;
- if ((bool) e.NewValue)
+ bool oldValue = (bool)e.OldValue;
+ bool newValue = (bool)e.NewValue;
+
+ if (newValue)
{
menuItem.OnChecked(new RoutedEventArgs(CheckedEvent));
}
@@ -954,6 +957,12 @@ private static void OnIsCheckedChanged(DependencyObject d, DependencyPropertyCha
{
menuItem.OnUnchecked(new RoutedEventArgs(UncheckedEvent));
}
+
+ MenuItemAutomationPeer peer = UIElementAutomationPeer.FromElement(menuItem) as MenuItemAutomationPeer;
+ if (peer != null)
+ {
+ peer.RaiseToggleStatePropertyChangedEvent(oldValue, newValue);
+ }
}
///
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs
index b39aea2cb2c..08c0e6c1e75 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs
@@ -942,17 +942,17 @@ private bool RaiseContextMenuOpeningEvent(IInputElement source, double x, double
DependencyObject sourceDO = source as DependencyObject;
if (userInitiated && sourceDO != null)
{
- if (InputElement.IsUIElement(sourceDO))
+ if (sourceDO is UIElement uiElement)
{
- ((UIElement)sourceDO).RaiseEvent(args, userInitiated);
+ uiElement.RaiseEvent(args, userInitiated);
}
- else if (InputElement.IsContentElement(sourceDO))
+ else if (sourceDO is ContentElement contentElement)
{
- ((ContentElement)sourceDO).RaiseEvent(args, userInitiated);
+ contentElement.RaiseEvent(args, userInitiated);
}
- else if (InputElement.IsUIElement3D(sourceDO))
+ else if (sourceDO is UIElement3D uiElement3D)
{
- ((UIElement3D)sourceDO).RaiseEvent(args, userInitiated);
+ uiElement3D.RaiseEvent(args, userInitiated);
}
else
{
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DatePickerTextBox.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DatePickerTextBox.cs
index c9fff7ac270..2b63c8484a7 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DatePickerTextBox.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DatePickerTextBox.cs
@@ -153,7 +153,7 @@ private T ExtractTemplatePart(string partName) where T : DependencyObject
private static T ExtractTemplatePart(string partName, DependencyObject obj) where T : DependencyObject
{
Debug.Assert(
- obj == null || typeof(T).IsInstanceOfType(obj),
+ obj == null || obj is T,
string.Format(CultureInfo.InvariantCulture, SR.Get(SRID.DatePickerTextBox_TemplatePartIsOfIncorrectType), partName, typeof(T).Name));
return obj as T;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DescendentsWalker.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DescendentsWalker.cs
index 8dbaa7d402c..7338bf29dfb 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DescendentsWalker.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DescendentsWalker.cs
@@ -56,8 +56,8 @@ public virtual void StartWalk(DependencyObject startNode, bool skipStartNode)
if (!skipStartNode)
{
- if (FrameworkElement.DType.IsInstanceOfType(_startNode) ||
- FrameworkContentElement.DType.IsInstanceOfType(_startNode))
+ if (_startNode is FrameworkElement
+ or FrameworkContentElement)
{
// Callback for the root of the subtree
continueWalk = _callback(_startNode, _data, _priority == TreeWalkPriority.VisualTree);
@@ -79,9 +79,8 @@ private void IterateChildren(DependencyObject d)
{
_recursionDepth++;
- if (FrameworkElement.DType.IsInstanceOfType(d))
+ if (d is FrameworkElement fe)
{
- FrameworkElement fe = (FrameworkElement) d;
bool hasLogicalChildren = fe.HasLogicalChildren;
// FrameworkElement have both a visual and a logical tree.
@@ -100,11 +99,10 @@ private void IterateChildren(DependencyObject d)
Debug.Assert( false, "Tree walk priority should be Visual first or Logical first - but this instance of DescendentsWalker has an invalid priority setting that's neither of the two." );
}
}
- else if (FrameworkContentElement.DType.IsInstanceOfType(d))
+ else if (d is FrameworkContentElement fce)
{
// FrameworkContentElement only has a logical tree, so we
// Walk logical children
- FrameworkContentElement fce = d as FrameworkContentElement;
if (fce.HasLogicalChildren)
{
WalkLogicalChildren( null, fce, fce.LogicalChildren );
@@ -114,18 +112,13 @@ private void IterateChildren(DependencyObject d)
{
// Neither a FrameworkElement nor FrameworkContentElement. See
// if it's a Visual and if so walk the Visual collection
- Visual v = d as Visual;
- if (v != null)
+ if (d is Visual v)
{
WalkVisualChildren(v);
}
- else
+ else if (d is Visual3D v3D)
{
- Visual3D v3D = d as Visual3D;
- if (v3D != null)
- {
- WalkVisualChildren(v3D);
- }
+ WalkVisualChildren(v3D);
}
}
@@ -324,12 +317,12 @@ private void WalkFrameworkElementLogicalThenVisualChildren(
for(int i = 0; i < count; i++)
{
Visual child = feParent.InternalGetVisualChild(i);
- if (child != null && FrameworkElement.DType.IsInstanceOfType(child))
+ if (child != null && child is FrameworkElement fe)
{
// For the case that both parents are identical, this node should
// have already been visited when walking through logical
// children, hence we short-circuit here
- if (VisualTreeHelper.GetParent(child) != ((FrameworkElement) child).Parent)
+ if (VisualTreeHelper.GetParent(child) != fe.Parent)
{
bool visitedViaVisualTree = true;
VisitNode(child, visitedViaVisualTree);
@@ -404,11 +397,11 @@ private void VisitNode(DependencyObject d, bool visitedViaVisualTree)
{
if (_recursionDepth <= ContextLayoutManager.s_LayoutRecursionLimit)
{
- if (FrameworkElement.DType.IsInstanceOfType(d))
+ if (d is FrameworkElement fe)
{
- VisitNode(d as FrameworkElement, visitedViaVisualTree);
+ VisitNode(fe, visitedViaVisualTree);
}
- else if (FrameworkContentElement.DType.IsInstanceOfType(d))
+ else if (d is FrameworkContentElement)
{
_VisitNode(d, visitedViaVisualTree);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DescendentsWalkerBase.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DescendentsWalkerBase.cs
index 86e62723dbd..50fe3198db9 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DescendentsWalkerBase.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DescendentsWalkerBase.cs
@@ -38,9 +38,8 @@ internal bool WasVisited(DependencyObject d)
{
DependencyObject logicalParent;
- if (FrameworkElement.DType.IsInstanceOfType(ancestor))
+ if (ancestor is FrameworkElement fe)
{
- FrameworkElement fe = ancestor as FrameworkElement;
logicalParent = fe.Parent;
// FrameworkElement
DependencyObject dependencyObjectParent = VisualTreeHelper.GetParent(fe);
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDSBuilder.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDSBuilder.cs
index fb6b94acf6b..5436049845f 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDSBuilder.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDSBuilder.cs
@@ -17,7 +17,7 @@ namespace System.Windows.Documents
using System.Windows.Markup;
using System.Windows.Shapes;
using System.Windows.Documents.DocumentStructures;
- using ds=System.Windows.Documents.DocumentStructures;
+ using Ds=System.Windows.Documents.DocumentStructures;
using System;
using System.Collections;
using System.Collections.Generic;
@@ -219,7 +219,7 @@ private void AddChildofFixedNodeinFlow(int[] childIndex, NamedElement ne)
private void SpecialProcessing(SemanticBasicElement sbe)
{
- ds.ListItemStructure listItem = sbe as ds.ListItemStructure;
+ Ds.ListItemStructure listItem = sbe as Ds.ListItemStructure;
if (listItem != null && listItem.Marker != null)
{
NameHashFixedNode fen;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs
index eca91af6199..ac7c8d4ab04 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs
@@ -586,7 +586,7 @@ public void GetEmbedded(int index, ref Guid guidService, ref Guid riid, out obje
}
// See msdn's ITextStoreACP documentation for a full description.
- public void QueryInsertEmbedded(ref Guid guidService, int formatEtc, out bool insertable)
+ public void QueryInsertEmbedded(ref Guid guidService, IntPtr formatEtc, out bool insertable)
{
#if true
//
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElement.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElement.cs
index 95274b6d670..325623a60d2 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElement.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElement.cs
@@ -2233,8 +2233,10 @@ protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
{
//let incrementally-updating FrameworkElements to mark the vicinity of the affected child
//to perform partial update.
- if(FrameworkElement.DType.IsInstanceOfType(layoutParent))
- ((FrameworkElement)layoutParent).ParentLayoutInvalidated(this);
+ if(layoutParent is FrameworkElement fe)
+ {
+ fe.ParentLayoutInvalidated(this);
+ }
if (affectsParentMeasure)
{
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkContentElement.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkContentElement.cs
index c49f4b1f165..801648178a4 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkContentElement.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkContentElement.cs
@@ -1218,19 +1218,6 @@ internal event InheritedPropertyChangedEventHandler InheritedPropertyChanged
#endregion Internal Properties
- //------------------------------------------------------
- //
- // Internal Fields
- //
- //------------------------------------------------------
-
- #region Internal Fields
-
- // Optimization, to avoid calling FromSystemType too often
- internal new static DependencyObjectType DType = DependencyObjectType.FromSystemTypeInternal(typeof(FrameworkContentElement));
-
- #endregion Internal Fields
-
//------------------------------------------------------
//
// Private Fields
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkElement.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkElement.cs
index 1066e2efac8..c5ab045f7c3 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkElement.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkElement.cs
@@ -1267,19 +1267,6 @@ internal event InheritedPropertyChangedEventHandler InheritedPropertyChanged
#endregion Internal Properties
- //------------------------------------------------------
- //
- // Internal Fields
- //
- //------------------------------------------------------
-
- #region Internal Fields
-
- // Optimization, to avoid calling FromSystemType too often
- internal new static DependencyObjectType DType = DependencyObjectType.FromSystemTypeInternal(typeof(FrameworkElement));
-
- #endregion Internal Fields
-
//------------------------------------------------------
//
// Private Fields
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/Storyboard.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/Storyboard.cs
index 073e59f15f3..34d61b14856 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/Storyboard.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/Storyboard.cs
@@ -929,13 +929,13 @@ private bool PropertyCloningRequired( object targetPropertyValue )
///
private void VerifyComplexPathSupport( DependencyObject targetObject )
{
- if( FrameworkElement.DType.IsInstanceOfType(targetObject) )
+ if(targetObject is FrameworkElement)
{
// FrameworkElement and derived types are supported.
return;
}
- if( FrameworkContentElement.DType.IsInstanceOfType(targetObject) )
+ if(targetObject is FrameworkContentElement)
{
// FrameworkContentElement and derived types are supported.
return;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StyleHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StyleHelper.cs
index 9d76b939e4e..508435ee9d9 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StyleHelper.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StyleHelper.cs
@@ -2327,15 +2327,15 @@ internal static void SpecialDowncastToFEorFCE(DependencyObject d,
out FrameworkElement fe, out FrameworkContentElement fce,
bool throwIfNeither)
{
- if (FrameworkElement.DType.IsInstanceOfType(d))
+ if (d is FrameworkElement frameworkElement)
{
- fe = (FrameworkElement)d;
+ fe = frameworkElement;
fce = null;
}
- else if (FrameworkContentElement.DType.IsInstanceOfType(d))
+ else if (d is FrameworkContentElement frameworkContentElement)
{
fe = null;
- fce = (FrameworkContentElement)d;
+ fce = frameworkContentElement;
}
else if (throwIfNeither && !(d is System.Windows.Media.Media3D.Visual3D) )
{
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs
index a109668b0e1..1489ff80f3b 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs
@@ -1000,7 +1000,7 @@ private static bool OnInheritablePropertyChanged(
// only then do we need to Invalidate the property
if (BaseValueSourceInternal.Inherited >= oldEntry.BaseValueSourceInternal)
{
- if (visitedViaVisualTree && FrameworkElement.DType.IsInstanceOfType(d))
+ if (visitedViaVisualTree && d is FrameworkElement)
{
DependencyObject logicalParent = LogicalTreeHelper.GetParent(d);
if (logicalParent != null)
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationUI/PresentationUI.csproj b/src/Microsoft.DotNet.Wpf/src/PresentationUI/PresentationUI.csproj
index 421b0514185..2cb661f507d 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationUI/PresentationUI.csproj
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationUI/PresentationUI.csproj
@@ -216,7 +216,6 @@
-
diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentSequenceSerializer.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentSequenceSerializer.cs
index 83c6e68732e..e1496822ee8 100644
--- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentSequenceSerializer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentSequenceSerializer.cs
@@ -194,7 +194,7 @@ SerializablePropertyContext serializablePropertyContext
propertyValue);
- if (typeof(Type).IsInstanceOfType(propertyValue))
+ if (propertyValue is Type)
{
int index = valueAsString.LastIndexOf('.');
valueAsString = string.Concat(
diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentSequenceSerializerAsync.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentSequenceSerializerAsync.cs
index 1f1225bbd6f..e0c04abbfc7 100644
--- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentSequenceSerializerAsync.cs
+++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentSequenceSerializerAsync.cs
@@ -232,7 +232,7 @@ SerializablePropertyContext serializablePropertyContext
propertyValue);
- if (typeof(Type).IsInstanceOfType(propertyValue))
+ if (propertyValue is Type)
{
int index = valueAsString.LastIndexOf('.');
valueAsString = string.Concat(
diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedDocumentSerializer.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedDocumentSerializer.cs
index a85bd29b31b..ed8cfff47de 100644
--- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedDocumentSerializer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedDocumentSerializer.cs
@@ -277,7 +277,7 @@ SerializablePropertyContext serializablePropertyContext
propertyValue);
- if (typeof(Type).IsInstanceOfType(propertyValue))
+ if (propertyValue is Type)
{
int index = valueAsString.LastIndexOf('.');
valueAsString = string.Concat(
diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedDocumentSerializerAsync.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedDocumentSerializerAsync.cs
index 477f4cc6198..249da14c521 100644
--- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedDocumentSerializerAsync.cs
+++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedDocumentSerializerAsync.cs
@@ -317,7 +317,7 @@ SerializablePropertyContext serializablePropertyContext
propertyValue);
- if (typeof(Type).IsInstanceOfType(propertyValue))
+ if (propertyValue is Type)
{
int index = valueAsString.LastIndexOf('.');
valueAsString = string.Concat(
diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedPageSerializer.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedPageSerializer.cs
index 76d6e3c1413..ff1899ab917 100644
--- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedPageSerializer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedPageSerializer.cs
@@ -350,7 +350,7 @@ SerializablePropertyContext serializablePropertyContext
propertyValue);
- if (typeof(Type).IsInstanceOfType(propertyValue))
+ if (propertyValue is Type)
{
int index = valueAsString.LastIndexOf('.');
valueAsString = string.Concat(
diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedPageSerializerAsync.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedPageSerializerAsync.cs
index 186f5d0bee0..8cd45d0fa58 100644
--- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedPageSerializerAsync.cs
+++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedPageSerializerAsync.cs
@@ -322,7 +322,7 @@ SerializablePropertyContext serializablePropertyContext
propertyValue);
- if (typeof(Type).IsInstanceOfType(propertyValue))
+ if (propertyValue is Type)
{
int index = valueAsString.LastIndexOf('.');
valueAsString = string.Concat(
diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMFixedPageSerializer.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMFixedPageSerializer.cs
index bf5204f9bfd..fd1b65885fc 100644
--- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMFixedPageSerializer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMFixedPageSerializer.cs
@@ -308,7 +308,7 @@ SerializablePropertyContext serializablePropertyContext
propertyValue);
- if (typeof(Type).IsInstanceOfType(propertyValue))
+ if (propertyValue is Type)
{
int index = valueAsString.LastIndexOf('.');
valueAsString = string.Concat(
diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/UnsafeNativeMethodsTextServices.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/UnsafeNativeMethodsTextServices.cs
index 4de87412c39..389a273ea5b 100644
--- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/UnsafeNativeMethodsTextServices.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/UnsafeNativeMethodsTextServices.cs
@@ -1630,7 +1630,7 @@ void SetText(SetTextFlags flags, int start, int end,
//HRESULT QueryInsertEmbedded([in] const GUID *pguidService,
// [in] const FORMATETC *pFormatEtc,
// [out] BOOL *pfInsertable);
- void QueryInsertEmbedded(ref Guid guidService, int /*ref Win32.FORMATETC*/ formatEtc, [MarshalAs(UnmanagedType.Bool)] out bool insertable);
+ void QueryInsertEmbedded(ref Guid guidService, IntPtr /*ref Win32.FORMATETC*/ formatEtc, [MarshalAs(UnmanagedType.Bool)] out bool insertable);
///
//HRESULT InsertEmbedded([in] DWORD dwFlags,
@@ -1972,14 +1972,14 @@ void SetText(int ec, /*SetTextFlags*/ int flags,
// [out] LONG *pcch,
// [in, unique] const TF_HALTCOND *pHalt);
///
- void ShiftStart(int ec, int count, out int result, int ZeroForNow); // "ZeroForNow" should be a struct ptr if we ever use this
+ void ShiftStart(int ec, int count, out int result, IntPtr pHalt);
//HRESULT ShiftEnd([in] TfEditCookie ec,
// [in] LONG cchReq,
// [out] LONG *pcch,
// [in, unique] const TF_HALTCOND *pHalt);
///
- void ShiftEnd(int ec, int count, out int result, int ZeroForNow); // "ZeroForNow" should be a struct ptr if we ever use this
+ void ShiftEnd(int ec, int count, out int result, IntPtr pHalt);
//HRESULT ShiftStartToRange([in] TfEditCookie ec,
// [in] ITfRange *pRange,
@@ -2117,14 +2117,14 @@ void SetText(int ec, /*SetTextFlags*/ int flags,
// [out] LONG *pcch,
// [in, unique] const TF_HALTCOND *pHalt);
///
- void ShiftStart(int ec, int count, out int result, int ZeroForNow); // "ZeroForNow" should be a struct ptr if we ever use this
+ void ShiftStart(int ec, int count, out int result, IntPtr pHalt);
//HRESULT ShiftEnd([in] TfEditCookie ec,
// [in] LONG cchReq,
// [out] LONG *pcch,
// [in, unique] const TF_HALTCOND *pHalt);
///
- void ShiftEnd(int ec, int count, out int result, int ZeroForNow); // "ZeroForNow" should be a struct ptr if we ever use this
+ void ShiftEnd(int ec, int count, out int result, IntPtr pHalt);
//HRESULT ShiftStartToRange([in] TfEditCookie ec,
// [in] ITfRange *pRange,
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Printing/System.Printing.vcxproj b/src/Microsoft.DotNet.Wpf/src/System.Printing/System.Printing.vcxproj
index 08aefddac41..5183124e00d 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Printing/System.Printing.vcxproj
+++ b/src/Microsoft.DotNet.Wpf/src/System.Printing/System.Printing.vcxproj
@@ -31,6 +31,11 @@
.NETCoreApp
v6.0
Unknown
+
+ true
diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/Compoundfile/CompoundFileDeflateTransform.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/Compoundfile/CompoundFileDeflateTransform.cs
index 397a0cdd96d..fddf844935b 100644
--- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/Compoundfile/CompoundFileDeflateTransform.cs
+++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/Compoundfile/CompoundFileDeflateTransform.cs
@@ -23,7 +23,7 @@
using MS.Internal.IO.Packaging; // for PackagingUtilities
using System.Security; // for SecurityCritical and SecurityTreatAsSafe
using MS.Internal.WindowsBase;
-using static Interop.zlib; // workaround namespace collision with MS.Internal.interop
+using static Interop.Zlib; // workaround namespace collision with MS.Internal.interop
namespace MS.Internal.IO.Packaging.CompoundFile
{
diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherOperation.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherOperation.cs
index 766a619dc20..9ef8dfa13d2 100644
--- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherOperation.cs
+++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherOperation.cs
@@ -425,7 +425,7 @@ internal void Invoke()
EventHandler handler; // either completed or aborted
lock(DispatcherLock)
{
- if(_exception != null && _exception is OperationCanceledException)
+ if(_exception is OperationCanceledException)
{
// A new way to abort/cancel an operation is to raise an
// OperationCanceledException exception. This only works