npolyak / NP.Ava.UniDock

New (Avalonia 11) UniDock repository
MIT License
154 stars 10 forks source link

Dock in UserControl gives NullReferenceException #9

Closed cirrusone closed 9 months ago

cirrusone commented 9 months ago

Great project, thanks.

Is there an example of using UniDock in a UserControl rather than Window? I want to add the same dock layout to multiple different windows so have added UniDock to a UserControl.

It builds and opens but when moving DockItem the following error is raised as it's looking for a Window

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=NP.Ava.UniDock

at location NP.Ava.UniDock\DockManager.cs

private static bool IsGroupOperating(IDockGroup group)
{
    var v = group.GetVisual();
    return v.IsVisible &&
        (v as ILogical).IsAttachedToLogicalTree && 
        v.GetControlsWindow<Window>().IsVisible;
}

I've tried changing the binding to refer to the parent window by changing the following but still get the same issue

np:DockAttachedProperties.DockChildWindowOwner="{Binding RelativeSource={RelativeSource Mode=Self}}"

to np:DockAttachedProperties.DockChildWindowOwner="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"

Is it possible to use this within a UserControl rather than Window?

cirrusone commented 9 months ago

Apologies, this looks like an issue my end. I added the styles to the Window rather than Application,

eg this creates problems only when attempting to move the tabbed windows ->

    <Window.Styles>
        <StyleInclude Source="avares://NP.Ava.Visuals/Themes/TextStyles.axaml"/>
        <StyleInclude Source="avares://NP.Ava.Visuals/Themes/CustomWindowStyles.axaml"/>
        <StyleInclude Source="avares://NP.Ava.UniDock/Themes/DockStyles.axaml"/>
    </Window.Styles>

this works fine ->

    <Application.Styles>
        <StyleInclude Source="avares://NP.Ava.Visuals/Themes/TextStyles.axaml"/>
        <StyleInclude Source="avares://NP.Ava.Visuals/Themes/CustomWindowStyles.axaml"/>
        <StyleInclude Source="avares://NP.Ava.UniDock/Themes/DockStyles.axaml"/>
    </Application.Styles>
npolyak commented 9 months ago

Sorry for the delay answering you - I did not have time to look into it during the week. Yes, using UniDock inside a UserControl is pretty much the same as using it inside a window.

Regards,

Nick