UserControl as Content for HeaderedContentControl.HeaderTemplate

会有一股神秘感。 提交于 2019-12-12 02:14:14

问题


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:


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



来源:https://stackoverflow.com/questions/3205338/usercontrol-as-content-for-headeredcontentcontrol-headertemplate

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!