Accesssing controls in a frame via pagechanging function

Wizard for WPF Forum

Posted 15 years ago by Craig Doggett
Version: 4.5.0480
Avatar
I have awizard form with a standard interior wizard page. The wizard page loads a frame from another xaml file that contains that pages controls. In my wizard form cs file in the page changing function I want to access the controls from the wizard page frame. If I add controls directly to the wizard page I can access them, but can't access them from within the frame.

How can I do this?? Below are excerpts from my project. Thanks!!



My Wizard Form... Here is a wizard page that loads a frame.

<wizard:WizardPage PageType="Interior" FontSize="20" FontFamily="Comic Sans MS" CancelButtonVisible="True">

<Frame Background="Transparent" Name="frame1" Source="InvWizSelectItemsFrame.xaml" />

</wizard:WizardPage>

-------------------------------------------------------------

In may wizard form cs file...

private void Inventorywizard_SelectedPageChanging(object sender, WizardSelectedPageChangeEventArgs e)
{
// choose inv products
if (this.Inventorywizard.SelectedPage == SelectItems)
{
validate controls here...
}
}
-------------------------------------------------------------

<Page x:Class="Achiever.InvWizSelectItemsFrame"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:jas="clr-namespace:WPF.JoshSmith.Controls;assembly=WPF.JoshSmith"

Title="Page1" Height="470" Background="Transparent">

Controls...
More controls...

</Page>

Comments (4)

Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Craig,

We haven't done too much work with the Frame control however my guess would be that you would either recurse down the logical or visual tree of Frame or Page, using LogicalTreeHelper or VisualTreeHelper.

Our VisualTreeHelperExtended has some nice helper features that go above and beyond what VisualTreeHelper does too.


Actipro Software Support

Posted 15 years ago by Craig Doggett
Avatar
Hi, Could you please be a little more specific when you say traverse down the visual tree of Frame or Page. What would you suggest I look for??

Thanks,
Craig
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Since you are loading the controls on the fly, you will need to search for the controls you need to access. WPF stores the visible controls in a tree structure, which you can traverse (and search) using VisualTreeHelper. VisualTreeHelper has methods like GetChildrenCount and GetChild. You can use those to iterate down the visual tree.

Hope that helps... but note that this question would probably be better answered in a general WPF forum since it doesn't really relate specifically to our controls. This is a great forum with an active user community:
http://social.msdn.microsoft.com/forums/en-US/wpf/threads/


Actipro Software Support

Posted 15 years ago by Craig Doggett
Avatar
Thanks for the suggestion. That was the key. The code below retrieves all the checkbox controls on the page specified by e.OldSelectedPage in the pagechanging method.

IList<DependencyObject> obj = VisualTreeHelperExtended.GetAllDescendants(e.OldSelectedPage, typeof(CheckBox));

Craig
The latest build of this product (v24.1.2) was released 1 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.