tags:

views:

385

answers:

4

I am new to WPF programming model. I have few queries:

  1. Does Page tag in XAML (in an XBAP application) is of type FrameworkElement?

  2. if i have a child element lets say Frame inside a Page. I pass that frame element in a function in another assembly. Now i try to navigate back to the Page from Frame control's Parent property i am not able to get a reference to Page? Any thoughts?

A: 
  1. Yes, just like everything else in XAML. Go here for the official documentation.
Gerrie Schenck
+1  A: 
  1. Yes, Page inherits from FrameworkElement.
  2. Sometimes going up the tree is not as easy as simply checking the parent, especially if you are using Templates. If you are using templates, you need to go up the tree using the Parent property until it is null. Then, use the TemplatedParent property. You can walk up the logical tree using a combination of both. That being said, WPF provides helper methods for this very scenario. Check out LogicalTreeHelper.GetParent.
siz
Thanks for the reply.Page getTopParent(FrameworkElement f){ FrameworkElement ct = f; while (true) { if (ct is Page) { break; } ct = (FrameworkElement)ct.Parent; } return ct as Page; }
Thanks, well i have just checked and i think it doesn't matter whether i am passing it in same assembly or another one. Yes, my Page element contains control and data templates? Is there any way i can get the parent page even if i have templates in my Page.
A: 

Hi,

The function which i am using in another assembly to get the parent Page of child control

Page getTopParent(FrameworkElement f) { FrameworkElement ct = f; while (true) { if (ct is Page) { break; } ct = (FrameworkElement) ct.Parent; } return ct as Page; }

A: 
Please find example XAML

-->

        </TabControl.ItemTemplate>
        <TabControl.ContentTemplate>
            <DataTemplate>
                <StackPanel HorizontalAlignment="Left">
                    <Frame Name="tabContent" Height="520" Width="820" local:WebBrowserBehavior.Source="{Binding Path=CurrentPage}" ContentRendered="tabItem_contentRendered"/>
                </StackPanel>
            </DataTemplate>
        </TabControl.ContentTemplate>
    </TabControl>
    <StackPanel Orientation="Horizontal" Name="taskBar" Height="34" VerticalAlignment="Bottom">
        <Button Height="23" Name="helpButton" Width="43" Content="Help" Click="helpButton_Click"/>
    </StackPanel>
</StackPanel>

Take a look at my response.
siz