NavigationBar how to get an internal element

Navigation for WPF Forum

Posted 8 years ago by Arthur Damen
Version: 10.2.0533
Avatar
Hi,
I am trying to get a destinationstreeviewcontrol instance from the window. The Items are created by binding. If I ask the navbar.selectedpane i get an item from the 'someconnections' in stead of a reference to the destinationstreeviewcontrol which i need. What Am i doing wrong here? Thanks.

Style & Datatemplate:

    <Style x:Key="NavigationGroupStyle" TargetType="{x:Type an:NavigationPane}">
      <Setter Property="ContentTemplate">
        <Setter.Value>
          <DataTemplate>
            <ContentControl >
              <Grid x:Name="ContentGrid"  >
                <controls:DestinationsTreeViewControl x:Name="TvUcDestinations" Tag="{Binding}"  MouseLeftButtonUp="TvUcDestinations_MouseLeftButtonUp"/>
              </Grid>
            </ContentControl>
          </DataTemplate>
        </Setter.Value>
      </Setter>
    </Style>
Element

      <an:NavigationBar x:Name="NavBar" HorizontalAlignment="Stretch"
                        IsHeaderContentVisible="True" SelectionChanged="NavBar_SelectionChanged" ItemContainerStyle="{StaticResource NavigationGroupStyle}" >
      </an:NavigationBar>
Event

  Private Sub NavBar_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs)
Dim P As NavigationPane = NavBar.SelectedPane '????????
End Sub
load window

NavBar.ItemsSource = My.SomeConnections

Comments (5)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Arthur,

I believe this article will help you, as it tells how to find ControlTemplate-generated elements:
http://msdn.microsoft.com/en-us/library/bb613586.aspx


Actipro Software Support

Posted 8 years ago by Arthur Damen
Avatar
I am trying now to get the datatemplate from the selection changed event (navbar).
However the datatemplate is not filled in (Nothing)

The datatemplate example uses an itemtemplate, where i use a ItemContainerStyle. Could this be the problem?

        Dim CurrentPane As NavigationPane = CType(NavBar.ItemContainerGenerator.ContainerFromItem(NavBar.SelectedItem), NavigationPane)
        Dim myContentPresenter As ContentPresenter = FindVisualChild(Of ContentPresenter)(CurrentPane)
        Dim Dt As DataTemplate = myContentPresenter.ContentTemplate

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Arthur,

While I haven't tried it here, I would imagine that based on the article, you'd want to do something like:
Dim tv = CurrentPane.Template.FindName("TvUcDestinations", CurrentPane);
If that doesn't work and if you still can't figure it out, please make a new simple sample project that shows the issue and email that to our support address so we can take a look. Make sure you rename the .zip file extension so it doesn't get spam blocked.


Actipro Software Support

Posted 8 years ago by Arthur Damen
Avatar
Hi,
This also did not work. For now I made a work around at start to get all treeviews (loaded event) and save them in a list so I know which are there...
I'm loosing to much time at this moment.

When I have time i will create a seperate test project and come back, or maybe i get a good brainwave :)

Thanks.
Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Arthur,

Keep in mind that the DataTemplate may not be created until after the SelectionChanged event. We are just using a ContentPresenter and passing the content/DataTemplate to that. I believe that creates the DataTemplate during the measure/arrange phase of the ContentPresenter.

You may need to dispatch the code that looks for your control, so it occurs after the layout has occured. Alternatively, you can use an attached behavior for your control to know when it is added/removed from the visual tree.


Actipro Software Support

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.