Browse Source

ExpanderAutomationPeer WIP

add-expanderAutomationPeer
Daniil Pavliuchyk 3 years ago
parent
commit
c58039cec9
  1. 5
      samples/Sandbox/MainWindow.axaml
  2. 64
      src/Avalonia.Controls/Automation/Peers/ExpanderAutomationPeer.cs
  3. 7
      src/Avalonia.Controls/Expander.cs

5
samples/Sandbox/MainWindow.axaml

@ -1,4 +1,9 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
x:Class="Sandbox.MainWindow">
<Expander Header="Expand Up" ExpandDirection="Up">
<StackPanel>
<TextBlock>Expanded content</TextBlock>
</StackPanel>
</Expander>
</Window>

64
src/Avalonia.Controls/Automation/Peers/ExpanderAutomationPeer.cs

@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using Avalonia.Automation;
using Avalonia.Automation.Peers;
using Avalonia.Automation.Provider;
namespace Avalonia.Controls.Automation.Peers
{
public class ExpanderAutomationPeer : ControlAutomationPeer, IExpandCollapseProvider
{
public ExpanderAutomationPeer(Expander owner) : base(owner)
{
owner.PropertyChanged += Owner_PropertyChanged;
}
protected override string? GetNameCore()
{
return base.GetNameCore();
}
protected override string GetClassNameCore()
{
return "Expander";
}
protected override bool IsContentElementCore() => true;
protected override bool IsControlElementCore() => true;
protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.Group;
}
public ExpandCollapseState ExpandCollapseState => ((Expander)Owner).IsExpanded ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed;
public bool ShowsMenu => throw new NotImplementedException();
public void Collapse()
{
if (!IsEnabled())
throw new ElementNotEnabledException();
((Expander)Owner).IsExpanded = false;
}
public void Expand()
{
if (!IsEnabled())
throw new ElementNotEnabledException();
((Expander)Owner).IsExpanded = true;
}
private void Owner_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)
{
if (e.Property == Expander.IsExpandedProperty)
{
RaisePropertyChangedEvent(
ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
(bool)e.OldValue! ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed,
(bool)e.NewValue! ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed);
}
}
}
}

7
src/Avalonia.Controls/Expander.cs

@ -1,6 +1,8 @@
using System;
using System.Threading;
using Avalonia.Animation;
using Avalonia.Automation.Peers;
using Avalonia.Controls.Automation.Peers;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Data;
@ -274,6 +276,11 @@ namespace Avalonia.Controls
}
}
protected override AutomationPeer OnCreateAutomationPeer()
{
return new ExpanderAutomationPeer(this);
}
/// <summary>
/// Updates the visual state of the control by applying latest PseudoClasses.
/// </summary>

Loading…
Cancel
Save