Files
PropertyGrid/Examples/AdvancedExample/MainWindow.axaml.cs
T
2026-08-10 14:46:18 +02:00

52 lines
1.4 KiB
C#

using Avalonia.Controls;
using Avalonia.LogicalTree;
using AdvancedExample.Models;
namespace AdvancedExample;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var config = new AdvancedConfiguration();
DataContext = config;
// Find the PropertyGrid and set its SelectedObject directly
this.Opened += (s, e) =>
{
var propertyGrid = this.FindDescendantOfType<Avalonia.PropertyGrid.Controls.PropertyGrid>();
if (propertyGrid != null)
{
propertyGrid.SelectedObject = config;
System.Diagnostics.Debug.WriteLine("AdvancedExample: PropertyGrid found and SelectedObject set directly");
}
else
{
System.Diagnostics.Debug.WriteLine("AdvancedExample: PropertyGrid NOT found!");
}
};
}
}
public static class ControlExtensions
{
public static T? FindDescendantOfType<T>(this Control control) where T : class
{
if (control is T result)
return result;
foreach (var child in control.GetLogicalChildren())
{
if (child is Control childControl)
{
var found = FindDescendantOfType<T>(childControl);
if (found != null)
return found;
}
}
return null;
}
}