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

DockingTabControl doesn't work when within a UserControl #2

Open
Kryptos-FR opened this issue Aug 24, 2024 · 0 comments
Open

DockingTabControl doesn't work when within a UserControl #2

Kryptos-FR opened this issue Aug 24, 2024 · 0 comments

Comments

@Kryptos-FR
Copy link

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant