i have 2 page i need to navigate mainpage.xaml to login.page xaml but it throws me Object reference not set to an instance of an object. in Root.Children.Clear();....
i added this codes in App.xaml:
private void Application_Startup(object sender, StartupEventArgs e)
{
Grid myGrid = new Grid();
myGrid.Children.Add(new MainPage());
this.RootVisual = myGrid;
}
and than i adde some codes on main.xaml to navigate to LoginUI.xaml
namespace Gen.CallCenter.UI
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
Grid Root = ((Grid)(this.Parent));
Root.Children.Clear();
Root.Children.Add(new LoginUI());
}
}
}
How can i navigate main.xaml to LoginUI.xaml ?
Try this:
It's working for me. :)
Like AnthonyWJones said you need to use the navigation framework.
First you'll need to add a reference to
System.Windows.Controls.Navigation
in your project and refernce it in you MainPage.xamlThen you'll need a frame within where you'll switch different XAML pages. Something like this:
Now somewhere in MainPage.xaml you could have a Button with a tag
<Button Click="Button_Click" Tag="/Views/Second.xaml" Content="Second" />
and in the
Button_Click
eventhandler you could switch out the content showed innavFrame
.A cool thing to note is that by using NavigationFramework the browser back and forward buttons work perfectly and the URL in the addressbar updates depending on the XAML page you are currently on :)
The simple one to solve this problem, you can look at this website : http://blogs.microsoft.co.il/blogs/eladkatz/archive/2011/01/25/adapting-silverlight-navigation-to-mvvm.aspx .
I had this problem to earlier. But after I read this tutorial, I can easily navigating to another view with MVVM. Hope this can help you all solve the problem.Thx
Let's suppose you are viewing the
MainPage.xaml
then you want to open another xaml page callednewPage.xaml
by clicking on aButton
or anImageEdit
in theMainPage.xaml
, here's the quick solution that you should write inside theMainPage.xaml.cs
:This is working with me.
Looks like you've started off on the wrong foot. This sort of thing is catered for using the Navigation application template. You should start a new project and select "Silverlight Navigation Application".
Once loaded just run it to see what the basic shell looks like. Then take a look at how MainPage is structured and say the Home view. What you will need to do is create new views based on the navigation
Page
type and then add them to MainPage.xaml.