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

DockingManager.LayoutItemTemplateSelector is applied twice because... #422

Open
Mona04 opened this issue Feb 3, 2023 · 0 comments
Open

Comments

@Mona04
Copy link
Contributor

Mona04 commented Feb 3, 2023

The TemplateSelector which is bind to DockingManager.LayoutItemTemplateSelector has SelectTemplate() like below.

public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
    return null;
}

When it is first fired, item is ContentPresenter and container has in Content other ContentPresenter which has an actual item in Content.

When second, it worked as expected.

I think it is because of line 763 in generic.xaml.

<Style TargetType="{x:Type avalonDockControls:LayoutDocumentControl}">
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type avalonDockControls:LayoutDocumentControl}">
					<Border
						Background="{TemplateBinding Background}"
						BorderBrush="{TemplateBinding BorderBrush}"
						BorderThickness="{TemplateBinding BorderThickness}">
						<ContentPresenter
							Content="{Binding LayoutItem.View, RelativeSource={RelativeSource TemplatedParent}}"
// should deleted
							ContentTemplate="{Binding LayoutItem.View.ContentTemplate, RelativeSource={RelativeSource TemplatedParent}}" 
// should deleted 
							ContentTemplateSelector="{Binding LayoutItem.View.ContentTemplateSelector, RelativeSource={RelativeSource TemplatedParent}}" />
					</Border>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>

Or I think LayoutItem.View should not create ContentPresenter and add an override function OnApplyTemplate() of LayoutItem like below.

  public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            // Template should have ContentPresenter with a name of  PART_Content
            _view= Template.FindName("PART_Content", this) as ContentPresenter;
            LayoutElement.Root.Manager?.InternalAddLogicalChild(_view);
        }

and generic.xaml is revised like below.

   <Style TargetType="{x:Type dockctrl:LayoutDocumentControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type dockctrl:LayoutDocumentControl}">
                    <Border
						Background="{TemplateBinding Background}"
						BorderBrush="{TemplateBinding BorderBrush}"
						BorderThickness="{TemplateBinding BorderThickness}">
                        <!--ContentPresenter
							Content="{Binding LayoutItem.View, RelativeSource={RelativeSource TemplatedParent}}"/-->
                        <ContentPresenter x:Name="PART_Content" 
                            Content="{Binding LayoutItem.LayoutElement.Content,  RelativeSource={RelativeSource TemplatedParent}}"
							ContentTemplate="{Binding LayoutItem.LayoutElement.Root.Manager.LayoutItemTemplate, RelativeSource={RelativeSource TemplatedParent}}" 
							ContentTemplateSelector="{Binding LayoutItem.LayoutElement.Root.Manager.LayoutItemTemplateSelector, RelativeSource={RelativeSource TemplatedParent}}" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
@Mona04 Mona04 changed the title DockingManager.LayoutItemTemplateSelector send item with ContentPresenter Why a layout item of DockingManager is in Content of ContentPresenter of ContentPresenter? Feb 3, 2023
@Mona04 Mona04 changed the title Why a layout item of DockingManager is in Content of ContentPresenter of ContentPresenter? DockingManager.LayoutItemTemplateSelector is applied twice. Feb 3, 2023
@Mona04 Mona04 changed the title DockingManager.LayoutItemTemplateSelector is applied twice. DockingManager.LayoutItemTemplateSelector is applied twice because... Feb 3, 2023
Mona04 added a commit to Mona04/AvalonDock that referenced this issue Feb 3, 2023
@Mona04 Mona04 mentioned this issue Feb 3, 2023
Dirkster99 added a commit that referenced this issue Mar 24, 2023
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