Skip to content

Commit

Permalink
Propertly handle an InlineUIContainer's logical children
Browse files Browse the repository at this point in the history
  • Loading branch information
Gillibald committed Feb 3, 2023
1 parent a19b43d commit 6210018
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Avalonia.Controls.DataGrid/DataGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3979,7 +3979,7 @@ private void DataGrid_LostFocus(object sender, RoutedEventArgs e)
{
if (focusedObject is Control element)
{
parent = element.Parent;
parent = element.VisualParent;
if (parent != null)
{
dataGridWillReceiveRoutedEvent = false;
Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.Controls.DataGrid/Utils/TreeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal static bool ContainsChild(this Visual element, Visual child)
{
if (child is Control childElement)
{
parent = childElement.Parent;
parent = childElement.VisualParent;
}
}
child = parent;
Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ protected bool HasFocus()
Control? element = focused as Control;
if (element != null)
{
parent = element.Parent;
parent = element.VisualParent;
}
}
focused = parent;
Expand Down
4 changes: 0 additions & 4 deletions src/Avalonia.Controls/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
using System.Collections.Generic;
using System.ComponentModel;
using Avalonia.Automation.Peers;
using Avalonia.Controls.Documents;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Input;
using Avalonia.Input.Platform;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Avalonia.Media;
using Avalonia.Rendering;
using Avalonia.Styling;
using Avalonia.Threading;
Expand Down Expand Up @@ -211,8 +209,6 @@ public event EventHandler<SizeChangedEventArgs>? SizeChanged
remove => RemoveHandler(SizeChangedEvent, value);
}

public new Control? Parent => (Control?)base.Parent;

/// <inheritdoc/>
bool IDataTemplateHost.IsDataTemplatesInitialized => _dataTemplates != null;

Expand Down
18 changes: 18 additions & 0 deletions src/Avalonia.Controls/Documents/InlineUIContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,23 @@ internal override void BuildTextRun(IList<TextRun> textRuns)
internal override void AppendText(StringBuilder stringBuilder)
{
}

protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);

if (change.Property == ChildProperty)
{
if(change.OldValue is Control oldChild)
{
LogicalChildren.Remove(oldChild);
}

if(change.NewValue is Control newChild)
{
LogicalChildren.Add(newChild);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ protected void SelectItemAndAncestors(IMenuItem item)
}
}

protected static IMenuItem? GetMenuItem(Control? item)
protected static IMenuItem? GetMenuItem(StyledElement? item)
{
while (true)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.Controls/Primitives/OverlayPopupHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool IPopupHost.Topmost
set { /* Not currently supported in overlay popups */ }
}

protected internal override Interactive? InteractiveParent => Parent;
protected internal override Interactive? InteractiveParent => (Interactive?)VisualParent;

public void Dispose() => Hide();

Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.Controls/Primitives/Popup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ private void CloseCore()

while (e is object && (!e.Focusable || !e.IsEffectivelyEnabled || !e.IsVisible))
{
e = e.Parent;
e = e.VisualParent as Control;
}

if (e is object)
Expand Down
4 changes: 2 additions & 2 deletions src/Avalonia.Controls/Primitives/PopupRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ public Transform? Transform
/// <remarks>
/// Popup events are passed to their parent window. This facilitates this.
/// </remarks>
protected internal override Interactive? InteractiveParent => Parent;
protected internal override Interactive? InteractiveParent => (Interactive?)Parent;

/// <summary>
/// Gets the control that is hosting the popup root.
/// </summary>
Visual? IHostedVisualTreeRoot.Host => Parent;
Visual? IHostedVisualTreeRoot.Host => VisualParent;

/// <summary>
/// Gets the styling parent of the popup root.
Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.Controls/ProgressBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
private void UpdateIndicator()
{
// Gets the size of the parent indicator container
var barSize = _indicator?.Parent?.Bounds.Size ?? Bounds.Size;
var barSize = _indicator?.VisualParent?.Bounds.Size ?? Bounds.Size;

if (_indicator != null)
{
Expand Down
4 changes: 0 additions & 4 deletions src/Avalonia.Controls/TextBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,6 @@ protected override Size MeasureOverride(Size availableSize)
controlRun.Control is Control control)
{
VisualChildren.Remove(control);

LogicalChildren.Remove(control);
}
}
}
Expand All @@ -693,8 +691,6 @@ protected override Size MeasureOverride(Size availableSize)
{
VisualChildren.Add(control);

LogicalChildren.Add(control);

control.Measure(Size.Infinity);
}
}
Expand Down

0 comments on commit 6210018

Please sign in to comment.