Skip to content
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

DevTools should not add visual elements to its logical tree #17443

Open
wants to merge 1 commit into
base: master
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
7 changes: 7 additions & 0 deletions src/Avalonia.Controls/ContentControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public VerticalAlignment VerticalContentAlignment
set => SetValue(VerticalContentAlignmentProperty, value);
}

internal virtual bool AddContentToLogicalTree => true;

/// <inheritdoc/>
IAvaloniaList<ILogical> IContentPresenterHost.LogicalChildren => LogicalChildren;

Expand Down Expand Up @@ -142,6 +144,11 @@ protected virtual bool RegisterContentPresenter(ContentPresenter presenter)

private void ContentChanged(AvaloniaPropertyChangedEventArgs e)
{
if (!AddContentToLogicalTree)
{
return;
}

if (e.OldValue is ILogical oldChild)
{
LogicalChildren.Remove(oldChild);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using Avalonia.Controls;

namespace Avalonia.Diagnostics.Controls
{
internal class ControlDetailsContentControl : ContentControl
{
protected override Type StyleKeyOverride => typeof(ContentControl);

internal override bool AddContentToLogicalTree => false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,13 @@
<StackPanel Orientation="Horizontal" Spacing="2" HorizontalAlignment="Left">
<TextBlock Classes="property-name" PointerPressed="PropertyNamePressed" Text="{Binding Name}" />
<TextBlock Text=":" />
<ContentControl Content="{Binding Value}">
<controls:ControlDetailsContentControl Content="{Binding Value}">
<ContentControl.ContentTemplate>
<DataTemplate x:DataType="system:Object">
<TextBlock Text="{Binding}" />
</DataTemplate>
</ContentControl.ContentTemplate>
</ContentControl>
</controls:ControlDetailsContentControl>
<TextBlock>(</TextBlock>
<Ellipse Height="8" Width="8" VerticalAlignment="Center" Fill="{Binding Tint}" ToolTip.Tip="{Binding ValueTypeTooltip}"/>
<TextBlock FontStyle="Italic" Text="{Binding Key}" />
Expand All @@ -288,13 +288,13 @@
<StackPanel Orientation="Horizontal" Spacing="2">
<TextBlock Classes="property-name" PointerPressed="PropertyNamePressed" Text="{Binding Name}" />
<TextBlock Text=":" />
<ContentControl Content="{Binding Value}">
<controls:ControlDetailsContentControl Content="{Binding Value}">
<ContentControl.ContentTemplate>
<DataTemplate x:DataType="system:Object">
<TextBlock Text="{Binding}" />
</DataTemplate>
</ContentControl.ContentTemplate>
</ContentControl>
</controls:ControlDetailsContentControl>
</StackPanel>
<Rectangle Classes="property-inactive" IsVisible="{Binding !IsActive}" />
</Panel>
Expand Down
Loading