Everybody.
In UWP Windows 10, I want to get the current navigated page in frame as object.
So I can call some methods from that page.
I have main page that is updating some model in async mode, but binding is not updating controls. I need to call:
Bindings.Update();
on page that is currently navigated in the frame in order to update some TextBlocks.
How to manage this?
Related
Need to refresh Root frame control once network is disconnected in terminal.
Steps:
If login successful, it redirect to Home page.
Inside home view, child frame set to navigate to another page, but home view is act as master page, it constant.
Now I accessing any child page, but in between if network is disconnected, then it should notify to home view control for status color change.
Can any one suggest.
You should tell us which part is confusing that makes you cannot finish your task. Here are something related:
I have no idea why network status changed is related to child and main frame. Personally I would register the NetworkStatusChanged event to detect the network status.
I'm not so sure whether you've noticed the official sample. In any official sample you can find this code:
rootPage.NotifyUser
Actually the NotifyUser method is defined in mainpage and then in the demo page you will call the following code(A simple demo):
MainPage rootPage = MainPage.Current;
So if your network changes, you just need to detect the event and then call the rootframe's method to change the color.
https://msdn.microsoft.com/en-us/magazine/jj694937.aspx
Using MVVM Messenger concept, it help to Send back to my parent page control to refresh.
I've tried a number of approaches to this, but when trying to navigate between one page and another in Windows 10 I'm getting some strange behaviour. I display my first page in app.xaml.cs:
View.MainPageView mp = new View.MainPageView();
Window.Current.Content = mp;
This displays the main page fine; however, I have a command that does effectively the same thing for my second page:
View.SecondView dv = new View.SecondView();
Window.Current.Content = dv;
What happens is that it displays the second page, but it is blank. When I try to inspect it using XAML Spy, it shows that the page is there; however, there is no content for it at all (that is, no controls showing).
Is there something particular about Windows 10 that might explain this or, alternatively, is there something about overriding the content in this way that might explain this behaviour?
EDIT:
It appears that the issue is caused by using a bound command, rather than a handled even in order to navigate; the following code works on a click event:
Frame rootFrame = Window.Current.Content as Frame;
rootFrame.Navigated += RootFrame_Navigated;
rootFrame.Navigate(typeof(View.SecondView), null);
But when called from a bound command, whilst it still shows the view, it is always blank. I initially thought this might be relating to the calling thread, but using the UI thread dispatcher makes no difference.
Windows 10 uses the same approach like 8.1.
If you create a new project in Visual Studio and open App.xaml.cs you can find there OnLaunched method. Inside this method you can see that instance of Frame is created and assigned to Window.Current.Content. Frame will help you to manage whole navigation. At the end of this method is navigation to the MainPage.
rootFrame.Navigate(typeof(MainPage), e.Arguments);
If you want to navigate to the second page from the main page, you have to use:
Frame.Navigate(typeof(SecondPage));
In order to go back to the main page just call:
if (Frame.CanGoBack)
{
Frame.GoBack();
}
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 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.