Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6924103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:37:14+00:00 2026-05-27T10:37:14+00:00

I’m using the Silverlight business application (Navigation application) template that comes with Visual studio

  • 0

I’m using the Silverlight business application (Navigation application) template that comes with Visual studio 2010. I have 3 pages in my app ..Home, About and Contact.

Now my requirement is that, based on a certain configuration setting stored in the web.config file, retrieved via an async WCF call, I need to do 2 things via code behind
1. Add HyperLinks to the one or more of the above pages
2. And also make the content frame in the MainPage.Xaml to load a particular page by default

My MainPage.Xaml looks like following

<UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
         x:Class="MainPage"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

            <StackPanel x:Name="LinksStackPanel"
                        Style="{StaticResource LinksStackPanelStyle}">
            </StackPanel>

            <navigation:Frame x:Name="ContentFrame"
                              Navigated="ContentFrame_Navigated"
                              NavigationFailed="ContentFrame_NavigationFailed">
                <navigation:Frame.UriMapper>
                    <uriMapper:UriMapper>
                        <uriMapper:UriMapping Uri=""
                                              MappedUri="/Views/Home.xaml" />
                        <uriMapper:UriMapping Uri="/{pageName}"
                                              MappedUri="/Views/{pageName}.xaml" />
                        <uriMapper:UriMapping MappedUri="/Views/{pageName}.xaml"
                                              Uri="{}{pageName}" />
                    </uriMapper:UriMapper>
                </navigation:Frame.UriMapper>
            </navigation:Frame>

In my code behind of MainPage.xaml.cs I do the following

    /// <summary>
    /// Default constructor
    /// </summary>
    public MainPage()
    {
        InitializeComponent();
        Loaded += new RoutedEventHandler(MainPage_Loaded);
    }

    void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        // Determine if deployed in TEST or PROD
        Client.IsTestCompleted += new EventHandler<IsTestCompletedEventArgs>(Client_IsTestCompleted);
        client.IsTestAsync();
    }

    void Client_IsTestCompleted(object sender, IsTestCompletedEventArgs e)
    {
        MainPage.IsTest = e.Result;

        if (MainPage.IsTest)
        {
            // Add hyperling to About page
            this.AddHyperLink("About", "about");

            // load about.xaml in the content frame
            this.ContentFrame.Source = new Uri("About", UriKind.Relative);
        }
        else
        {
            // Add hyperlinks to Home, contact and About page
            this.AddHyperLink("Home", "home");
            this.AddHyperLink("Contact", "contact");
            this.AddHyperLink("About", "about");


            // load about.xaml in the content frame
            this.ContentFrame.Source = new Uri("About", UriKind.Relative);
        }
    }

    private void AddHyperLink(string uri, string content)
    {
        HyperlinkButton hb = new HyperlinkButton();
        hb.NavigateUri = new Uri(uri, UriKind.RelativeOrAbsolute);
        hb.TargetName = "ContentFrame";
        hb.Content = content;
        hb.Style = Application.Current.Resources["LinkStyle"] as Style;
        this.LinksStackPanel.Children.Add(hb);
    }

So this working as expected. That is when I start the application it loads the about page only when deployed in test and when deployed in prod shows 3 links with content frame navigated to about page.

But the problem is, the constructor of the HomePage, Home_Loaded and OnNavigatedTo() are getting called from somewhere before the similar methods in AboutPage are called.

This is wasting a lot of time bcoz, it unnecessarily execute the code in these methods when its not being loaded in the frame

This is code in Home.Xaml.cs

public Home()
    {
        InitializeComponent();
        Loaded += new RoutedEventHandler(Home_Loaded);
    }

    /// <summary>
    /// Load the home page
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void Home_Loaded(object sender, RoutedEventArgs e)
    {
      //Expensive code
    }

    /// <summary>
    /// Executes when the user navigates to this page.
    /// </summary>
    /// <param name="e"></param>
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
       //Expensive code
    }

So my questions are…

  1. Who is calling these methods in HomePage and why? Since I was loading about.xaml in the content frame I dont expect any code in HomePage to execute but only the code in About.xaml

  2. And what do i need to do to make sure that these methods in the HomePage are not executed on application load but only when navigated to that page by clicking on “Home” link.

  3. Is there a better way to achieve this navigation problem , other than setting the source of the content frame

Thanks for the help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:37:14+00:00Added an answer on May 27, 2026 at 10:37 am

    I did what Rikkos suggested. Changed the Uri mapping of default page to an empty page and it works like a charm now

    <uriMapper:UriMapper>
                        <uriMapper:UriMapping Uri=""
                                              MappedUri="/Views/EmptyPage.xaml" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.