Skip to content

Stop duplicating Scroll code in TreeViewAutomationPeer / forward to base #10883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,24 @@ protected ItemsControlAutomationPeer(ItemsControl owner): base(owner)
///
public override object GetPattern(PatternInterface patternInterface)
{
if(patternInterface == PatternInterface.Scroll)
if (patternInterface is PatternInterface.Scroll)
{
ItemsControl owner = (ItemsControl)Owner;
if(owner.ScrollHost != null)
if (owner.ScrollHost is not null)
{
AutomationPeer scrollPeer = UIElementAutomationPeer.CreatePeerForElement(owner.ScrollHost);
if(scrollPeer != null && scrollPeer is IScrollProvider)
AutomationPeer scrollPeer = CreatePeerForElement(owner.ScrollHost);
if (scrollPeer is IScrollProvider scrollProvider)
{
scrollPeer.EventsSource = this;
return (IScrollProvider)scrollPeer;
return scrollProvider;
}
}
}
else if (patternInterface == PatternInterface.ItemContainer)
else if (patternInterface is PatternInterface.ItemContainer)
{
if(Owner as ItemsControl != null)
if (Owner is ItemsControl)
return this;

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,12 @@ protected override string GetClassNameCore()
///
public override object GetPattern(PatternInterface patternInterface)
{
if (patternInterface == PatternInterface.Selection)
if (patternInterface is PatternInterface.Selection)
{
return this;
}
else if(patternInterface == PatternInterface.Scroll)
{
ItemsControl owner = (ItemsControl)Owner;
if(owner.ScrollHost != null)
{
AutomationPeer scrollPeer = UIElementAutomationPeer.CreatePeerForElement(owner.ScrollHost);
if(scrollPeer != null && scrollPeer is IScrollProvider)
{
scrollPeer.EventsSource = this;
return (IScrollProvider)scrollPeer;
}
}
}

// PatternInterface.Scroll is handled by ItemsControlAutomationPeer
return base.GetPattern(patternInterface);
}

Expand Down Expand Up @@ -164,12 +152,7 @@ IRawElementProviderSimple[] ISelectionProvider.GetSelection()
}
}

if (selection == null)
{
selection = Array.Empty<IRawElementProviderSimple>();
}

return selection;
return selection ?? Array.Empty<IRawElementProviderSimple>();
}

bool ISelectionProvider.CanSelectMultiple
Expand Down