Skip to content

CanClose setter of LayoutItem Style will not work if DataContext is set in xaml #505

@LJN-hzleaper

Description

@LJN-hzleaper

If I set Window.DataContext in code behind, everything is ok:

public MainWindow()
{
    InitializeComponent();
    DataContext = new MainViewModel();
}

But if I set Window.DataContext in xaml instead, CanClose setter of LayoutItem Style will not work, the cross button will show even if I set CanClose to false in style:

<Window.DataContext>
    <local:MainViewModel></local:MainViewModel>
</Window.DataContext>
...
<DockingManager.LayoutItemContainerStyleSelector>
    <views:PanesStyleSelector>
        <views:PanesStyleSelector.ToolStyle>
            <Style TargetType="{x:Type LayoutAnchorableItem}">
                <Setter Property="Title" Value="{Binding Model.Name}" />
                <Setter Property="CanClose" Value="True" />
                <Setter Property="CloseCommand" Value="{Binding Model.CmdClose}" />
                <Setter Property="Visibility"
                        Value="{Binding Model.IsVisible, Mode=TwoWay, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter={x:Static Visibility.Hidden}}" />
                <Setter Property="ContentId" Value="{Binding Model.ViewType}" />
            </Style>
        </views:PanesStyleSelector.ToolStyle>
        <views:PanesStyleSelector.FileStyle>
            <Style TargetType="{x:Type LayoutItem}">
                <Setter Property="Title" Value="{Binding Model.Name}" />
                <Setter Property="CanClose" Value="False" />
                <Setter Property="ContentId" Value="{Binding Model.ViewType}" />
            </Style>
        </views:PanesStyleSelector.FileStyle>
    </views:PanesStyleSelector>
</DockingManager.LayoutItemContainerStyleSelector>

Here is my demo project and a snapshot of this bug.

Image

BugDemo.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions