Hi,
I have a DockSite set up with the following style:
<DataTemplate x:Key="taskTemplate">
<tbviews:TaskView x:Name="taskView" />
</DataTemplate>
<!-- Document tabs -->
<Style x:Key="DocumentItemStyle" TargetType="{x:Type apdocking:DocumentWindow}">
<Setter Property="Title" Value="{Binding Label}" />
<Setter Property="ContentTemplate" Value="{StaticResource taskTemplate}" />
</Style>
Declared as follows (omitting some of the irrelevant parts):
<apdocking:DockSite
x:Name="dockSite"
DocumentItemsSource="{Binding Path=Tasks}"
DocumentItemContainerStyle="{DynamicResource DocumentItemStyle}"
>
<apdocking:SplitContainer>
<apdocking:Workspace>
<apdocking:TabbedMdiHost Name="contentContainer" />
</apdocking:Workspace>
</apdocking:SplitContainer>
</apdocking:DockSite>
This works great, for the most part - with the help of an attached behavior, the DocumentWindow's show up with the <tbviews:TaskView /> UserControl, and all functions as expected. However, I can't figure out how to access parts of the templated UserControl in code this way. The following code:
DockSite dockSite = (DockSite)FindName("dockSite"); // works fine
DocumentWindow taskWindow = dockSite.ContainerFromDocumentItem(task); // works fine
ContentPresenter myContentPresenter = taskWindow.FindVisualChild<ContentPresenter>(); // works fine
DataTemplate myDataTemplate = myContentPresenter.ContentTemplate; // works fine
object o1 = myDataTemplate.FindName("taskView", myContentPresenter); // returns null
doesn't work as expected - specifically, the last statement returns 'null', when I expect it to return a reference to the templated TaskView object.
Is there something that I'm missing? What's the correct way to get a reference to a templated object inside a DocumentWindow?
Thanks