WPF, UserControls & CAB

Topics: CAB & Smart Client Software Factory
Jul 19, 2008 at 5:23 AM
I'm struggling with the following:

The attached code works in a straight WPF application, however it does not seem to work in CAB.
What can I do to work around the problem?

I get the dreaded "This operation is valid only on elements that have this template applied." error.

(by the way, how do I attach code to my posting so it doesn't get garbled?)

(In View1.xaml.cs) 


void
TabControl_Loaded(object sender, RoutedEventArgs e)
{
    TabControl tabControl = sender as TabControl;
    if (tabControl != null)
    {
        
ContentPresenter cp = tabControl.Template.FindName("PART_SelectedContentHost", tabControl) as ContentPresenter;
        
TextBox tb = tabControl.ContentTemplate.FindName("tbContent", cp) as TextBox;
    }
}

(in View1.xaml)

<
UserControl
x:Class="what.Module1.View1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<UserControl.Resources>
<XmlDataProvider x:Key="myData" XPath="/Data">
<x:XData>
<Data xmlns="">
<Item id="1" value="1" />
<Item id="2" value="2" />
<Item id="3" value="3" />
<Item id="4" value="4" />
</Data>
</x:XData>
</XmlDataProvider>
</UserControl.Resources>
<Grid>
<TabControl ItemsSource="{Binding Source={StaticResource myData}, XPath=Item}"
Loaded="TabControl_Loaded">
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding XPath=@id}" />
</DataTemplate> \
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<TextBox Name="tbContent" Text="{Binding XPath=@value}" />
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
</Grid>
</
UserControl