Description
Sometimes it is useful to split a big UI into smaller UserControls. However, it doesn't currently work with this library because the DockingHost expects SplitPanels and DockingTabControls to be direct children of one another (
|
private void HandleChildrenModified(Control control, NotifyCollectionChangedEventArgs e) |
|
{ |
|
foreach (var child in e.OldItems?.OfType<Control>() ?? []) |
|
{ |
|
if (child is SplitPanel splitPanel) |
|
UnregisterSplitPanel(splitPanel); |
|
else if (child is TabControl tabControl) |
|
UnregisterTabControl(tabControl); |
|
} |
|
|
|
foreach (var child in e.NewItems?.OfType<Control>() ?? []) |
|
{ |
|
if (child is SplitPanel splitPanel) |
|
RegisterSplitPanelForDocking(splitPanel); |
|
else if (child is TabControl tabControl) |
|
RegisterTabControlForDocking(tabControl); |
|
} |
|
} |
).
While it is possible that doing a deep iteration of all children might be expensive and/or trigger unexpected behaviors, I do think that UserControl should be special cased and its children looked up.
Example expected to work
Adapting the sample from the README.
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:up="using:Avalonia.UpDock.Controls"
xmlns:view="using:MyProject"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="CODE_BEHIND_CLASS_GOES_HERE"
Title="Example">
<up:DockingHost>
<up:SplitPanel Fractions="1, 1" Orientation="Horizontal">
<up:DockingTabControl>
<TabItem Header="Tab A">
<TextBlock Margin="5">Content</TextBlock>
</TabItem>
</up:DockingTabControl>
<view:MyView />
</up:SplitPanel>
</up:DockingHost>
</Window>
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:up="using:Avalonia.UpDock.Controls"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="MyProject.MyView">
<up:DockingTabControl>
<TabItem Header="Tab B">
<TextBlock Margin="5">More content</TextBlock>
</TabItem>
<TabItem Header="Tab C">
<TextBlock Margin="5">Even more content</TextBlock>
</TabItem>
</up:DockingTabControl>
</UserControl>
Description
Sometimes it is useful to split a big UI into smaller
UserControls. However, it doesn't currently work with this library because theDockingHostexpectsSplitPanels andDockingTabControls to be direct children of one another (Avalonia.UpDock/Avalonia.UpDock/Controls/DockingHost.cs
Lines 101 to 118 in d749ec0
While it is possible that doing a deep iteration of all children might be expensive and/or trigger unexpected behaviors, I do think that
UserControlshould be special cased and its children looked up.Example expected to work
Adapting the sample from the README.