0

I have a UserControl in WPF which is having a TreeView inside it like below:

 <UserControl x:Class="SchemaElementsTree">
    <TreeView
        Name="tv1"
        ItemsSource="{Binding XPath=.}"
        ItemTemplate="{StaticResource rootTemplate}">
        <TreeView.ItemContainerStyle>
            <Style
                TargetType="{x:Type TreeViewItem}">
                <EventSetter
                    Event="MouseDoubleClick"
                    Handler="OnItemMouseDoubleClick" />
                <Setter
                    Property="IsExpanded"
                    Value="False"></Setter>
            </Style>
        </TreeView.ItemContainerStyle>
    </TreeView>
</UserControl>

This User Control is being used in another User Control where the data source for the Tree View is provided through Xml Data Provider as follows:

   <XmlDataProvider
    x:Key="xmlData"
    x:Name="xmlDataProvider"></XmlDataProvider>
<ScrollViewer
    DataContext="{StaticResource xmlData}">
    <uc:SchemaElementsTree x:Name="schemaTree"></uc:SchemaElementsTree>
</ScrollViewer>

Everything till this point is OK. Now, after the XmlDataProvider is loaded with an Xml File, the tree view shows the entire tree as one root node in the collapsed state. Clicking on the root node and further down works as expected expanding the corresponding node clicked.

What I need now is, I have an XPath which refers to a node in the Xml File I assigned to XmlDataProvider, and want a method that takes this XPath and makes that particular node visible in the Tree View.

I have tried enumerating the Items collection of the Tree View but it contains only a single Item which is the XmlDocument that was assigned to the XmlDataProvider. When I debug, I see that the TreeView.IsLoaded is False even after I have clicked on many nodes and expanded them.

What is happening here and how it can be done?

teenup
  • 7,459
  • 13
  • 63
  • 122

0 Answers0