jagguy
asked on
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.
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.
ASKER
>>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.
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.
Download project from following link. It has very basic page navigation.
http://www.c-sharpcorner.com/UploadFile/dhananjaycoder/pagenavigationsilverlight07072009060427AM/pagenavigationsilverlight.aspx
HTH
Ashok
http://www.c-sharpcorner.com/UploadFile/dhananjaycoder/pagenavigationsilverlight07072009060427AM/pagenavigationsilverlight.aspx
HTH
Ashok
ASKER
the example given is silverlight 2 and I believe silverlight 3 which I have is different again
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
To do this in new Page Navigation, watch video at
http://www.silverlight.net/learn/videos/silverlight-videos/navigation-framework/
HTH
Ashok
ASKER
I saw the video and downloaded the sample code and it doesnt work.
I am not sure if this is outdated or has errors.
I am not sure if this is outdated or has errors.
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
re-create the navigation application by following steps.
It will work with VS 2008 and Silverlight 3.0.
HTH
Ashok
Who else to read for Silverlight other than Mike Taulty!
http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/04/09/silverlight-3-and-navigation-applications.aspx
http://timheuer.com/blog/archive/2009/04/06/silverlight-3-navigation-behavior-customization.aspx
http://timheuer.com/blog/archive/2009/03/22/silverlight-navigation-framework-and-uri-routing.aspx
http://www.davidpoll.com/2009/07/14/silverlight-3-navigation-navigating-to-pages-in-dynamically-loaded-assemblies/
http://blogs.msdn.com/brada/archive/2009/07/31/silverlight-3-navigation-dynamically-loaded-pages-now-mef-powered.aspx
http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/04/09/silverlight-3-and-navigation-applications.aspx
http://timheuer.com/blog/archive/2009/04/06/silverlight-3-navigation-behavior-customization.aspx
http://timheuer.com/blog/archive/2009/03/22/silverlight-navigation-framework-and-uri-routing.aspx
http://www.davidpoll.com/2009/07/14/silverlight-3-navigation-navigating-to-pages-in-dynamically-loaded-assemblies/
http://blogs.msdn.com/brada/archive/2009/07/31/silverlight-3-navigation-dynamically-loaded-pages-now-mef-powered.aspx
ASKER
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
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-name space:Syst em.Windows .Controls; assembly=S ystem.Wind ows.Contro ls.Navigat ion"
xmlns:navigation="clr-name
<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>
ASKER
no my name spaces are the same except for
xmlns:local="clr-namespace :Silverlig htApplicat ion34"
which gives an error. did you try my code in VS2008?
xmlns:local="clr-namespace
which gives an error. did you try my code in VS2008?
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.Wind ows.Contro ls;assembl y=System.W indows.Con trols.Navi gation"
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.Wind
ASKER
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\A pp.xaml nav1
Error 1 The type 'ResourceDictionary' is inside a ResourceDictionary and does not have a key. D:\silverlight\nav1\nav1\A
<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>
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open new question, I will post complete project for Silverlight 3.0 with Page Navigation.
Ashok
Ashok
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