Invoke Root Frame control for Refresh - c#

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.

Related

Hide application in the OnBackButtonPressed event

I have 2 pages. LoginPage and ListPage.
In the LoginPage I ask for the credentials and the stores.
Then I see a list of information in ListPage.
What I want to get is that when I press the back button and capture the OnBackButtonPressed event, I want the application to hide and not return to the LoginPage page.
How can I do this?
Thank you very much for the help.
Instead of using NavigationPage you should directly be setting the MainPage for Navigation if you do not want to go back:
Application.Current.MainPage= new ListPage();
Or in the existing flow, you can close the current window in onBackPressed:
System.Diagnostics.Process.GetCurrentProcess().CloseMainWindow();
Or if you want to kill the process you can
System.Diagnostics.Process.GetCurrentProcess().Kill();

Xamarin.Forms Prism - Using navigation service to navigate from one detail page to another

In my Xamarin.Forms Prism app, I am using a MasterDetailPage for navigation.
While I am on one detail page, I would like to navigate to another detail page, as if I had selected it from the master page.
Initial navigation in App.xaml.cs:
protected override void OnInitialized()
{
...
NavigationService.NavigateAsync("MainPage/RootNavigation/MyFirstPage");
}
When I click a shortcut button on MyFirstPage, I would like to go to MainPage/RootNavigation/MySecondPage. The closest that I have been able to achieve has been using an absolute Uri.
private async void OnShortcutTapped(MyModel sender)
{
...
await _navigationService.NavigateAsync(new Uri("http://myapp.com/MainPage/RootNavigation/MySecondPage", UriKind.Absolute), navigationParams, null, false);
}
This basically gets me what I want, but after navigating in this manner, if I make the Master visible and select the menu item for MySecondPage, it refreshes the detail page as if it is navigating to the page.
Is there a better way to maintain this navigation, so that the master page knows that MySecondPage is already being displayed and it doesn't try to reload it?
While your navigation pattern doesn't make a lot of sense to me, you can achieve what you want by invoking a navigate command in the MasterDetailPageViewModel. You have a number of ways to do this. You could use the IEventAggregator to send a message to the MasterDetailPageViewModel to navigate, or you can use a CompositeCommand that invokes a DelegateCommand that exists on the MasterDetailPageViewModel.
You can see a sample of using a CompositeCommand here: https://github.com/PrismLibrary/Prism-Samples-Forms/tree/master/UsingCompositeCommands
You can also see how to send messages in this sample that I gave at the Xamarin Evolve conference: https://github.com/brianlagunas/Evolve2016SamplesAndSlides
Another option would be to just call a navigate command off the App.Current.MainPage ViewModel from with your MyFirstPage code behind.

Maps control SetView works only on the page's first load

I have a problem with Bing Maps control I use in my WP7 application.
When I'm navigated to the page with map control, it starts the GeoCoordinateWatcher. When GeoCoordinateWatcher has some location data for me, it calls a SetView() method to center the map at current location. There is also a button on ApplicationBar that's also starting the GeoCoordinateWatcher.
Now, the thing is, when I first navigate to this page, all works fine: GeoCoordinateWatcher starts, gives me the location data after some time, calls SetView() and the map centers when I need it too. The same with the button.
But if I press the Back button to get back to the main page and then try to navigate again to the map page, SetView() stops working. In debugging I see that the code surrounding it works as expected and the data passed to SetView() is correct, but nothing happens with the control and events for changing view don't fire either.
I'm assuming there may be something wrong with map initialization (or disposing on navigating from), but I don't know where to dig.
Edit:
I've tried changing Map.Center directly and it doesn't work in exactly the same way the SetView() doesn't: it works fine the first time page is navigated to and doesn't work on the other times.
Edit 2:
Ok, it gets weirder. In debugging I see that my map's center actually gets set to a correct value. But an actual control shows absolutely different location and me, moving map around, doesn't change the value that I see from code.
Edit 3:
I've added a button to ApplicationBar that just calls SetView() and it works fine. Apparently, the problem appears when I call SetView() as a result of GeoCoordinateWatcher.PositionChanged event raising. How could I work around that?
Try using map.Center = loc.CoOrdinates;
I've found the solution.
In my original code I've subscribed to the GeoCoordinateWatcher.Position property change event in the page constructor: App.PropertyChanged += AtmInfoPageOnAppPropertyChanged
All I had to do was to move that to the OnNavigatedTo event handler and add App.PropertyChanged -= AtmInfoPageOnAppPropertyChanged to the OnNavigatedFrom event handler.
I think, the problem was that keeping the old page subscribed to the event didn't allow it to be disposed, and at the same time didn't allow the new page to subscribe to that same event, thus causing the code to be called for the different page and different map control than the one displayed on the screen.

How to make a touchable notice top bar in windows phone?

How to make a touchable notice top bar in windows phone ?
I am new to C# and windows phone world.So may be my question has a simple
way to solve,but I google a lot ,and didn't work out.
here is my purpose: I have a timer running throughout my app,it request a
service for notice info every one hour, and show a "notice bar" on the top of
screen.
it is easy to get the information ,but when I want to show them to the Page,
here is my problem:
1.
I used system tray to show my info.
It works,but then I found there is no touch or click event for Progress
Indication bar.
I even add an event to Touch.FrameReported in App.xaml.cs , but still ,
when i touch the system tray area, the event doesn't fire.
2.
Then I want to use a Dynamic way to achieve it: add a text block to the
current page
I got the current page handler ,but case I only know the current page
handler's type is PhoneApplicationPage, I can't get my Root UI element
(all my page has a root element named "LayoutRoot")
And when I try to use reflect method to get the "LayoutRoot" property,
the return value is null.
The code looks like this :
Type type = PhoneApplicationPageHandler.getType()<
//I checked,the type is my page's type
type.getProperty("LayoutRoot") or type.getField("LayoutRoot")
//they all return null
BTW: LayoutRoot is a grid, and it is described in my page's .xmal file.
Now My option is to make all my page inherit a defalut page ,in this page ,I will
implement a method to fulfill my second way to simulate a "touchable top bar".
but I think this coding is ugly .
So, can anyone tell me :
1.how to add touch event to a SystemTray
or
2.how to get a handler of an ui element which is described in xaml, while I only have a PhoneApplicationPage type handler of that page.
You may use
1) a toast prompt described here http://windowsphonegeek.com/articles/WP7-Toast-Prompt-in-depth
2)or shell toast described here http://www.c-sharpcorner.com/UploadFile/ae35ca/working-with-toast-notification-in%C2%A0windows-phone-7/ according to what suits your requirement the best. 3)You may also create a custom control which you may place on the top on your mainPage and handle its tap event accordingly.

Navigate to existing instance of page in silverlight

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.

Categories

Resources