silverlight page switch

I am using silverlight and I am unsure about a better solution to my problem. I couldnt download a working example of this
http://www.silverlight.net/learn/videos/all/navigation-framework/

I have a game with say 2 levels and each level has a number of images.
I have a screen menu.

My current solution  is
I load the first level on mainpage.xaml.vb and when I goto the next level I erase all screen objects from level1 and then add all the level2 objects on the screen. So I am reusing the same page with different classes and images etc.
A screen menu was just a popup image I am using over the current level.

My desired solution is
What I wanted was to load the level 1 objects on page1.xaml.vb and level 2 objects on page2.xaml.vb with classes etc.
Switching levels would be to just signal what page to display and unload the other via another a mainPage.
jagguyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SriVaddadiCommented:
In the demo, he did not use Silverlight Navigation project but he added navigation functionality from scratch.

To make things easy, MS has a project template for Silverlight Navigation. This project provides basic infrastructure needed. Just check on that and you would get a direction to start on.

Not sure if this project was there with SL3 but it is there with SL4
jagguyAuthor Commented:
>>Silverlight Navigation. This project provides basic infrastructure needed. Just check on that and you >>would get a direction to start on.

OK I know the navigation template and without going into details I am not getting anywhere fast. The information supplied is confusing and examples on the web out dated. I cant find a basic example of page switching like my basic  example above so that is why i am asking here.
AshokSr. Software EngineerCommented:
Download project from following link.  It has very basic page navigation.

http://www.c-sharpcorner.com/UploadFile/dhananjaycoder/pagenavigationsilverlight07072009060427AM/pagenavigationsilverlight.aspx

HTH
Ashok
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

jagguyAuthor Commented:
the example given is silverlight 2 and I believe silverlight 3 which I have is different again
AshokSr. Software EngineerCommented:
It also works in Silverlight 3.0.

To do this in new Page Navigation, watch video at
http://www.silverlight.net/learn/videos/silverlight-videos/navigation-framework/

HTH
Ashok
jagguyAuthor Commented:
I saw the video and downloaded the sample code and it doesnt work.
I am not sure if this is outdated or has errors.
AshokSr. Software EngineerCommented:
Download may not be working, but you have to follow the video and
re-create the navigation application by following steps.

It will work with VS 2008 and Silverlight 3.0.

HTH
Ashok
jagguyAuthor Commented:
OK bets to work wit the code I have rather then link jumping for yet other ways of doing things. In my experience try a bit then ask for help otherwise you will waste time in google world.


Well I am getting an error on the bold liine in main.xaml. I have added page1.xaml and page2.xaml. I want to click a button in main and switch to a page1 or page2.

.Error    1    The tag 'Frame' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk'.    D:\silverlight\nav1\nav1\MainPage.xaml    13    10    nav1
Error    2    The type 'ResourceDictionary' is inside a ResourceDictionary and does not have a key.    D:\silverlight\nav1\nav1\App.xaml    nav1


main.xaml

<UserControl
    x:Class="nav1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
    xmlns:uriMapper="clr-namespace:System.Windows.Navigation;assembly=System.Windows.Controls.Navigation"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">

    <Grid x:Name="LayoutRoot" Margin="0">

        <sdk:Frame x:Name="Page1" UriMapper="{StaticResource GameUriMapper}"/>

    </Grid>

</UserControl>

app.xaml


<Application  
  x:Class="nav1.App"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:navigation="clr-namespace:System.Windows.Navigation;assembly=System.Windows.Controls.Navigation"
    
    >
    <Application.Resources>
        <navigation:UriMapper x:Key="GameUriMapper">

            <navigation:UriMapping Uri="{}{page}" MappedUri="/{page}.xaml"/>

        </navigation:UriMapper>



        <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Assets/Styles.xaml"/>
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </Application.Resources>

</Application>


main.xaml.vb

   Private Sub MainPage_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        bt.Width = 200
        bt.Height = 100
        AddHandler bt.Click, AddressOf bt_click

    End Sub

    Public Sub bt_click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        PageFrame.Navigate(New Uri("Level1", UriKind.Relative))
    End Sub

Open in new window

CodeCruiserCommented:
Looks like you are using the wrong namespace. This is the namespace used in one of the articles above and i have attached the code from main.xaml

xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"


<UserControl x:Class="SilverlightApplication34.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
    xmlns:local="clr-namespace:SilverlightApplication34">
    <Grid x:Name="LayoutRoot" Background="{StaticResource ApplicationBackgroundColorBrush}">
        <Grid.Resources>
            <local:VisibilityBooleanConverter x:Key="VisBool" />
        </Grid.Resources>

            <Grid Style="{StaticResource NavigationContainerStyle}">

            <Border Style="{StaticResource NavigationBorderStyle}">
            
                <StackPanel Style="{StaticResource NavigationPanelStyle}">

                    <Button Click="NavButton_Click" Tag="/Views/HomePage.xaml" Content="home" 
                            Style="{StaticResource PageLinkStyle}"/>
                    <Button Click="NavButton_Click" Tag="/Views/AboutPage.xaml" Content="about" 
                            Style="{StaticResource PageLinkStyle}"/>
                            
                            <Button Click="NavButton_Click" Tag="/Views/SubNavigation.xaml" Content="sub navigation" 
                            Style="{StaticResource PageLinkStyle}"/>
                
                </StackPanel>
            
            </Border>
            
            <Border Style="{StaticResource BrandingBorderStyle}">
            
                <StackPanel Style="{StaticResource BrandingPanelStyle}" x:Name="JournalNav">
                
                    <Button Content="back" Style="{StaticResource PageLinkStyle}" x:Name="NavBack" Click="NavBack_Click" />
                    <Button Content="forward" Style="{StaticResource PageLinkStyle}" x:Name="NavFwd" Click="NavFwd_Click" />

                </StackPanel>
                
            </Border>
            
        </Grid>

        <Border Style="{StaticResource FrameContainerStyle}">

            <Border Style="{StaticResource FrameInnerBorderStyle}">

                <navigation:Frame Navigated="Frame_Navigated" x:Name="Frame" Source="/Views/HomePage.xaml"
                                  HorizontalContentAlignment="Stretch"
                                  VerticalContentAlignment="Stretch"
                                  Padding="15,10,15,10"
                                  Background="White"/>

            </Border>

        </Border>

    </Grid>
</UserControl>

Open in new window

jagguyAuthor Commented:
no my name spaces are the same except for
  xmlns:local="clr-namespace:SilverlightApplication34"

which gives an error. did you try my code in VS2008?
CodeCruiserCommented:
No. I am not on my dev pc.

You are using <sdk:Frame where sdk refers to the namespace
"http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"

whereas in the tutorial, <navigation:Frame is used and navigation refers to the namespace
"clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
jagguyAuthor Commented:
I dont know what to do here because this was default code.

Error      1      The type 'ResourceDictionary' is inside a ResourceDictionary and does not have a key.      D:\silverlight\nav1\nav1\App.xaml      nav1

<Application   
  x:Class="nav1.App"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:navigation="clr-namespace:System.Windows.Navigation;assembly=System.Windows.Controls.Navigation"
  
    >
    <Application.Resources>
        <navigation:UriMapper x:Key="GameUriMapper">

            <navigation:UriMapping Uri="{}{page}" MappedUri="/{page}.xaml"/>

        </navigation:UriMapper>



        <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Assets/Styles.xaml"/>
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </Application.Resources>

</Application>

Open in new window

CodeCruiserCommented:
All I can say is go through the examples and try to build a simple small page first and if you succeed then implement it in your own app. You were supposed to be making changes in main.xaml not app.xaml I believe.
jagguyAuthor Commented:
Ok hang on here. The amount of time I have spent going through examples and NO ONE has pointed me to a complete example I can run in VS2008 that resembles anything like I need.

I AM buillding a small page.

In order to have a page switching ap I needed to add to app.xaml and i cant get around it as it is part of the solution. The error was in default code whci has nothong to do with what I typed in.

Why is it so hard get a simple page switching code in silverlight that switches actual pages and not frames. I dont know how to do this ! I just need a working framework.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AshokSr. Software EngineerCommented:
Open new question, I will post complete project for Silverlight 3.0 with Page Navigation.

Ashok
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.