Skip to content

Commit

Permalink
Merge pull request #3149 from MahApps/feature/GH-2527_CodedUI_and_Flyout
Browse files Browse the repository at this point in the history
Add FlyoutAutomationPeer for better CodedUI support
  • Loading branch information
punker76 committed Jan 14, 2018
2 parents 59d45bf + 5975d4c commit be61e1b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
Expand Up @@ -21,11 +21,20 @@ protected override AutomationControlType GetAutomationControlTypeCore()

protected override string GetNameCore()
{
string ownerTitle = ((BaseMetroDialog)this.Owner).Title;
string nameCore = base.GetNameCore();
if (!string.IsNullOrEmpty(ownerTitle))
if (string.IsNullOrEmpty(nameCore))
{
nameCore = $"{nameCore} {ownerTitle}";
nameCore = ((BaseMetroDialog)this.Owner).Title;
}

if (string.IsNullOrEmpty(nameCore))
{
nameCore = ((BaseMetroDialog)this.Owner).Name;
}

if (string.IsNullOrEmpty(nameCore))
{
nameCore = GetClassNameCore();
}

return nameCore;
Expand Down
6 changes: 6 additions & 0 deletions src/MahApps.Metro/MahApps.Metro.Shared/Controls/Flyout.cs
@@ -1,5 +1,6 @@
using System;
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
Expand Down Expand Up @@ -252,6 +253,11 @@ public Flyout()
this.InitializeAutoCloseTimer();
}

protected override AutomationPeer OnCreateAutomationPeer()
{
return new FlyoutAutomationPeer(this);
}

private void InternalCloseCommandExecuteAction(object o)
{
var closeCommand = this.CloseCommand;
Expand Down
@@ -0,0 +1,43 @@
using System.Windows.Automation.Peers;

namespace MahApps.Metro.Controls
{
public class FlyoutAutomationPeer : FrameworkElementAutomationPeer
{
public FlyoutAutomationPeer(Flyout owner)
: base(owner)
{
}

protected override string GetClassNameCore()
{
return "Flyout";
}

protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.Custom;
}

protected override string GetNameCore()
{
string nameCore = base.GetNameCore();
if (string.IsNullOrEmpty(nameCore))
{
nameCore = ((Flyout)this.Owner).Header as string;
}

if (string.IsNullOrEmpty(nameCore))
{
nameCore = ((Flyout)this.Owner).Name;
}

if (string.IsNullOrEmpty(nameCore))
{
nameCore = GetClassNameCore();
}

return nameCore;
}
}
}
Expand Up @@ -53,6 +53,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Controls\Extensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\FlipView.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Flyout.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\FlyoutAutomationPeer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\FlyoutsControl.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\FlyoutTheme.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Glow.cs" />
Expand Down

0 comments on commit be61e1b

Please sign in to comment.