Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1585
XamTree IsSelected not re-binding for Children Nodes Only
posted

I have a XamOutlookBar and the Content control is a XamTree

I try to set the selected node by using two way binding. The The 1 level works with no problem.

However, any children nodes never get marked as selected even though the model they are binding to denotes a single child node as selected. The Header text gets changed perfectly for all nodes, so I am pretty sure I have the binding set up right, just want to make sure I didn't make a mistake.

 

Here is my XAML

<igBar:XamOutlookBar
    HorizontalAlignment="Stretch"
    GroupsSource="{Binding Path=%objectpath%.Nodes}">
  <igBar:XamOutlookBar.DefaultGroupsContainer>
    <DataTemplate>
      <igBar:OutlookBarGroup IsSelected="True"/>
    </DataTemplate>
  </igBar:XamOutlookBar.DefaultGroupsContainer>
  <igBar:XamOutlookBar.GroupHeaderTemplate>
    <DataTemplate>
      <TextBlock Text="{Binding ItemName, Mode=TwoWay}"/>
    </DataTemplate>
  </igBar:XamOutlookBar.GroupHeaderTemplate>
  <igBar:XamOutlookBar.GroupContentTemplate>
    <DataTemplate>
      <igTree:XamTree ItemsSource="{Binding Path=Nodes}"
                  Margin="0"
                  Padding="0"
                  BorderBrush="#FF96B3DD"
                  Background="#FFFFFFFF"
                  ItemContainerStyle="{StaticResource XamTreeExpandedNodes}">
        <igTree:XamTree.DefaultItemsContainer>
          <DataTemplate>
            <igTree:XamTreeItem Visibility="{Binding Path=Visible, Mode=TwoWay}"
                                IsSelected="{Binding Path=IsSelected, Mode=TwoWay}"/>
          </DataTemplate>
        </igTree:XamTree.DefaultItemsContainer>
        <igTree:XamTree.HierarchicalItemTemplate>
          <ig:HierarchicalDataTemplate Template="{StaticResource XamTreeItemTemplate}"
                                       ItemsSource="{Binding Path=Nodes, Mode=TwoWay}">
            <!-- First Level -->
            <ig:HierarchicalDataTemplate.HierarchicalItemTemplate>
              <ig:HierarchicalDataTemplate Template="{StaticResource XamTreeItemTemplate}"
                                           ItemsSource="{Binding Path=Nodes, Mode=TwoWay}">
                <!-- Second Level -->
                <ig:HierarchicalDataTemplate.HierarchicalItemTemplate>
                  <ig:HierarchicalDataTemplate Template="{StaticResource XamTreeItemTemplate}"
                                               ItemsSource="{Binding Path=Nodes, Mode=TwoWay}">
                    <!-- Third Level -->
                  </ig:HierarchicalDataTemplate>
                </ig:HierarchicalDataTemplate.HierarchicalItemTemplate>
              </ig:HierarchicalDataTemplate>
            </ig:HierarchicalDataTemplate.HierarchicalItemTemplate>
          </ig:HierarchicalDataTemplate>
        </igTree:XamTree.HierarchicalItemTemplate>
      </igTree:XamTree>
    </DataTemplate>
  </igBar:XamOutlookBar.GroupContentTemplate>
  <igBar:XamOutlookBar.DefaultLargeIconTemplate>
    <DataTemplate>
      <Image VerticalAlignment="Center"
             Source="{Binding ImageUrl}" />
    </DataTemplate>
  </igBar:XamOutlookBar.DefaultLargeIconTemplate>
  <igBar:XamOutlookBar.DefaultSmallIconTemplate>
    <DataTemplate>
      <Image VerticalAlignment="Center"
             Source="{Binding ImageUrl}" />
    </DataTemplate>
  </igBar:XamOutlookBar.DefaultSmallIconTemplate>
</igBar:XamOutlookBar>

 

Here is my XamTreeItemTemplate

   <DataTemplate x:Name="XamTreeItemTemplate" >
        <StackPanel Orientation="Horizontal">
          <Image Source="{Binding ImageUrl}" />
          <HyperlinkButton
                  Content='{Binding ItemName, Mode=TwoWay}'
                  HorizontalAlignment='Left'
                  VerticalAlignment='Top'
                  Command="{Binding PostbackCommand}"
                  CommandParameter="{Binding GUID}"
                  Margin="2,0"
                  Foreground="Black"
                  IsTabStop="False">
          </HyperlinkButton>
        </StackPanel>
      </DataTemplate>

Any ideas?


  • 1585
    Verified Answer
    posted

    So to fix my issue I created a static resouce called XamTreeItemContainer

    <DataTemplate x:Name="XamTreeItemContainer">
            <igTree:XamTreeItem Visibility="{Binding Path=Visible, Mode=TwoWay}
                                IsSelected="{Binding Path=IsSelected, Mode=TwoWay}"/>
    </DataTemplate>

    And then set the property for each HierarchialDataTemplate like the following:

    <ig:HierarchicalDataTemplate Template="{StaticResource XamTreeItemTemplate}
                                           ItemsSource="{Binding Path=Nodes, Mode=TwoWay}"
                                           DefaultItemsContainer="{StaticResource XamTreeItemContainer}">

    That solved my issue.

    Thanks!