0

In WPF, I need to access the "myControl" from code-behind when it is defined in the Resources section like below

<ListView Name="myListView">
    <ListView.Resources>
         <Popup x:Key="myPopup" >
             <Border>
                 <StackPanel Orientation="Vertical">
                      <my:SomeControl Name="myControl" />
                 </StackPanel>
             </Border>
         </Popup>
    </ListView.Resources>
</ListView>

I am able to find the Popup resource with

Dim p As Popup = myListView.TryFindResource("myPopup")

...but how to continue to access what's inside the Popup, i.e. myControl in this case?

Nuts
  • 2,755
  • 6
  • 33
  • 78

1 Answers1

0

Popup's are not part of visual tree so instead you should traverse logical tree. You can get to control like this -

var someControl = LogicalTreeHelper.FindLogicalNode(p, "myControl");
Rohit Vats
  • 79,502
  • 12
  • 161
  • 185