views:

882

answers:

1

Hi, I hope someone out there can help me.

I have created a dropdown treeview using a treeview in a popup and displaying the selected item in a content control.

    <Grid Background="White" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<Grid.ColumnDefinitions>
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
    <RowDefinition Height="*"/>
</Grid.RowDefinitions> 
<ContentControl x:Name="SelectedItemCtrl" DataContext="{Binding ElementName=treeViewQryPopup, Path=SelectedItem}"  Content="{Binding}" Grid.Column="0" Background="White" MinWidth="100" Width="auto" />                                
<Button Grid.Column="1" Width="15" Height="25" x:Name="DropBtn" HorizontalAlignment="Right" Click="DropBtn_Click" >
    <Image Margin="0.5,0,0.5,0" Stretch="Uniform"  Source="/ToolbarImages/DropDownBtn.gif"/>
</Button>
</Grid>
    <Popup x:Name="treePopup" AllowsTransparency="True" Loaded="treePopup_Loaded"  MouseLeave="treePopup_MouseLeave">
 <TreeView Grid.ColumnSpan="2" MaxHeight="250" x:Name="treeViewQryPopup" ItemsSource="{Binding}" SelectedItemChanged="treeViewQryPopup_SelectedItemChanged">
     <TreeView.ItemContainerStyle>
  <Style TargetType="{x:Type TreeViewItem}">
      <Setter Property="IsExpanded" Value="true" />
      <Setter Property="IsSelected" Value="true" />
      <Setter Property="FontWeight" Value="Normal" />
      <Style.Triggers>
   <Trigger Property="IsSelected" Value="True">
       <Setter Property="FontWeight" Value="Bold" />
   </Trigger>
      </Style.Triggers>
  </Style>
     </TreeView.ItemContainerStyle>
 </TreeView>
    </Popup>

The tree is bound to an XML document and the content control is bound to the selected item.

There are also several templates available to both the tree and the content control

<HierarchicalDataTemplate DataType="NavToOneEntity" ItemsSource="{Binding XPath=NavToOneEntity|NavToManyEntity}">
            <TextBlock Background="Yellow" Text="{Binding XPath=@Name}" />
        </HierarchicalDataTemplate>
        <HierarchicalDataTemplate DataType="NavToManyEntity" ItemsSource="{Binding XPath=NavToOneEntity|NavToManyEntity}">
            <TextBlock Background="LightGreen" Text="{Binding XPath=@Name}" />
        </HierarchicalDataTemplate>
        <HierarchicalDataTemplate DataType="RootEntity" ItemsSource="{Binding XPath=NavToOneEntity|NavToManyEntity}">
            <TextBlock Background="LightBlue" Text="{Binding XPath=@Name}" />
        </HierarchicalDataTemplate>

The tamplates work fine on the treeview but the content control only uses the first selected template, even though the text changes when a new item is selected, the template doesnt change as the colour remains the same as the first template used

So is there any way to get the content control to use the correct template?

Any help will be appreciated

thanks

A: 

I'm coming against the same problem, and would be curious to know the answer. Why doesn't ContentControl respect the DataType and display the correct DataTemplate?

Justin