UserControl as Content for HeaderedContentControl.

2019-08-20 17:18发布

I have a UserControl that I have successfully been using as a header for presentations that involve a list which can be headered, using the xaml below:

<DockPanel >
    <uc:ListSubjectHeader Subject="{Binding DisplayName}" 
                          AddNewItemCommand="{Binding AddCommand}"
                           ImageSource="..."  />

<!-- other controls -->

</DockPanel>

I would like to use this same control in another presentation where it would be the content for the header in a HeaderedContentControl, and came up with this xaml to do that:

<HeaderedContentControl Content="{Binding Path=DetailViewDepartment}" >
    <HeaderedContentControl.HeaderTemplate>
        <DataTemplate  DataType="{x:Type vm:DepartmentSelectionViewModel}">
            <uc:ListSubjectHeader Subject="{Binding DisplayName}" ...  />

        </DataTemplate>
    </HeaderedContentControl.HeaderTemplate>
</HeaderedContentControl>

The visual elements show up the way I want them to, but data does not. I should note that I am using the same view model (vm:DepartmentSelectionViewModel) in a different control's DataTemplate in the same presentation, which I asked as a different question here. If you know the answer to this one you likely know the answer to that one too.

How can I fix this?

Cheers,
Berryl

1条回答
甜甜的少女心
2楼-- · 2019-08-20 18:04

The HeaderTemplate applies to the object in the Header property, not Content. Content uses the ContentTemplate, just like in the normal ContentControl.

查看更多
登录 后发表回答