In my MainPage I have 3 frames,and trying to change the page of my FrameMain(frame) to another page,the problem is that I am doing this in another page inside a second frame if I use
NavigationService.Navigate(new Uri("/View/CreateAcc.xaml", UriKind.Relative));
It loads my current frame with the page,but I want the FrameMain to load this page, so I tried:
MainPage main = new MainPage();
main.FrameMain.Navigate(new Uri("/View/CreateAcc.xaml", UriKind.Relative));
wich didn't do anything...
sorry about the confuse text if someone can help i only saw examples of changing pages inside the MainPage.
Change the way of doing to get what i wanted,instead of using frame implemented two WrapPanel at exactly the same position and used the property Visibility to put one Visible and the other Collapsed and vice verse to change Panel showing.
Related
How can I possibly change the source of a frame from other page when I click a button in an active page.
What I'm doing is In page1.xaml, I have a frame with a source displaying page2.xaml.Once I click a button in page2.xaml, I want to update the source of frame in page1.xaml to page3.xaml and the frame should display page3.xaml instead of page2.xaml.
As of now, I tried using
page1 pg1 = new page1();
pg1.frame.source = new Uri("page3.xaml",UriKind.Relative);
But it didn't display page3.xaml in the frame in page1.xaml.
I also tried
page1 pg1 = new page1();
pg1.frame.Navigate(new Uri("page3.xaml",UriKind.Relative));
but didn't work as well, page2.xaml remains the display of the frame.
First of all, it is unusual to have frame inside page. Usually you have frame inside MainWindow or Usercontrol, because Page is meant to be hosted inside frame.
Second, you can't just create new Page1 and use it's frame. This newly created Page1 exist only in memory and it is another instance that the one displayed.
Because it would be quite difficult to find the Frame from pages, there is NavigationService property in Page class.
NavigationService.Navigate(new Uri("page3.xaml",UriKind.Relative));
I am developing a WPF application where i have a MainWindow that has a Frame control and a Label Control inside it, i have set the source of the Frame control to one of the pages i have created, what i want is to be able to change the content of Label control (inside Main window) from my Page.xaml which is displayed inside the Frame control.
Here is an Image to further illustrate what i really want . excuse my drawing!!
Page page = new Page(this);
Framme.Content = page;
I have one ListView and ContentFrame (Frame Control) inside of my MainPage.xaml.
For example if I Navigate page Content.xaml to this ContentFrame and then I need to call Navigate from his Content.xaml. But Navigate have to change content of main application Frame (it is parental Frame).
How can I do this?
Keep a reference to your root frame somewhere - e.g. as a static property on the App class and use that to call Navigate(). Alternatively you can walk up the visual or perhaps also logical tree and find the next frame to get the reference.
On a Frame in silverlight I want to be able to navigate to an existing instance of a Page. In short this is what I want:
Page p = ...; // initialize the page and set some of the properties
contentframe.Navigate(p);
Instead of using an Uri from which the page is created.
Can this be achieved (as in WPF), or should the frame rather be replaced by a ContentControl?
Edit: More clarity: Is there a way that NavigationService.Navigate(object root) that is available in WPF can be simulated in silverlight?
You question seems really quite confused.
should the frame rather be replaced by a ContentControl?
That would imply that you don't have good reason to have the frame there in the first place and you aren't using a navigating framework. In which case certainly you should replace the Frame with something else.
If you can replace the frame with something else the there is no need for your "Page" to be of type Page, it may as well be a UserControl.
It can all boil do down to have this simple Xaml:-
<Border x:Name="content" />
and this cs:-
UserControl p = ...;
content.Child = p;
Edit:
You need to keep the frame therefore you can't replace it with a ContentControl.
You might just assign your Page directly to the Frame Content property. However I'm not sure what would happen if you then click the back button. I suspect it would navigate to the page prior to the page you replaced.
Another option would be to us a static service to push your page properties on to a stack, you page can then pop them off this stack when initialising. This would allow you to navigate using a Uri to your page.
The problem you are facing is the same problem that I am facing. An event happens outside the frame, and the page has no idea that the event has ocured, but it needs to be notified of that event.
Now what can be done is force the page within that frame to refresh itself or handle those events by 1: storing the page's state temporarily, and b) passing "commands" through the query string.
I have a layout MainPage.xaml in which i have images and a button.
On click of button i want another layout Top.xaml to be displayed such that MainPage.xaml becomes invisible.
I am new to Windows phone 7?
Can someone help out?
This depends on what you are looking to do. You can either navigate from MainPage.xaml to Top.xaml using
NavigationService.Navigate(new Uri("Top.xaml", UriKind.Relative));
If you just want to switch between layouts (i.e. not navigate to a whole new page) you can implement both layouts in one XAML page and switch between them using VisualStateManager. Create one state called "Main" and other called "Top" then switch from one to the other as follows:
VisualStateManager.GoToState(this, "Top", true);
It all depends on how you want to layout your code and also how you expect the back button to work. Using states means you will have to handle the back button yourself.