I'm Not good at English, Thanks in advance.
I have problem that i just cant figure out right now. I am trying to develop a UWP and im stuck implementing this functionality.
I have a Header(Navigation view) in NavPage, such as this.
As you know, The Header and The Frame in one page, frame load a View, When I click "Up" or other button(appbarButton), I want pass a Info to Frame's current page(is MainPage).
At frist, I want invoking a current page method by appBarbutton, need static.No
then, I want pass a info to that page, and handle it in OnNavigatedTo(NavigationEventArgs e)
here is problem.
this is code:
private void BackHome(object sender, RoutedEventArgs e)
{
ContentFrame.Navigate(typeof(MainPage), "*BackHome");
}
private void BackUp(object sender, RoutedEventArgs e)
{
ContentFrame.Navigate(typeof(MainPage), "*BackUp");
}
I try two buttons.
But...when I click this appbar button,it is work, info pass success, but because Navigate() method, the frame's current page is reload, Parameters passed before useless
How pass info and don't reload?
any ideas? thanks every body.
Navigate might actually not be the best suited method to call since what it actually does is telling your frame to read the content of the specified Page, something that you only want to do when your specified page is different from the one you're currently in.
Edit 1.
Do you really need to pass information to the page for the situations where you're going to keep using the same content as your frame? If not, and just in order to stop the reloading for those situations, just check if you are actually calling the Navigate method to another page.
if(ContentFrame.SourcePageType != typeof(MainPage))
ContentFrame.Navigate(typeof(MainPage), "*BackUp");
Related
I have 3 BladeItems in another page. And I want to navigate from MainPage to that page and bring the requested BladeItem into view. But it is not working.
I first thought it was because that the page has not been loaded. So I put it into the Page_Loaded. However, it is still now working. Why is that?
private void Page_Loaded(object sender, RoutedEventArgs e)
{
TitleBarHelper.SetDarkTitleBar();
Window.Current.SetTitleBar(AppTitleBar);
UpdateTitleBarLayout(Windows.ApplicationModel.Core.CoreApplication.GetCurrentView().TitleBar);
FullMediaControl.Update();
SetMusic(MediaHelper.CurrentMusic);
FullPlaylistControl.ScrollToMusic(MediaHelper.CurrentMusic);
if (MusicInfoRequestedWhenUnloaded)
{
MusicPropertyBladeItem.StartBringIntoView();
MusicInfoRequestedWhenUnloaded = false;
}
else if (LyricsRequestedWhenUnloaded)
{
LyricsBladeItem.StartBringIntoView();
LyricsRequestedWhenUnloaded = false;
}
}
Source Page Code is here. This page can be navigated using the "Show Lyrics" or "Music Info" item in the MenuFlyout at the right bottom more button.
And actually the FullPlaylistControl.ScrollToMusic in the code above is also not working. It just scrolls to a row in a ListView. I guess they might be the same reason.
This is the documentation for StartBringIntoView.
According to the instructions in the documentation, this method is only possible when the control is rendered on the visual tree, so you need to modify it when you call the method.
You want MusicPropertyBladeItem.StartBringIntoView() to work, you need to call it in the MusicPropertyBladeItem_Loaded event. For the same reason, you need to call ScrollToMusic when the FullPlaylistControl is loaded.
Page_Loaded only means that the page is loaded, but it doesn't mean that the controls have been rendered.
Best ragards.
i want to navigate txtBox1.text and bg2.source to another xaml at the same time
i try to use this
private void button1_Click(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof(MultiGame), bg2.Source);
this.Frame.Navigate(typeof(MultiGame), txtBox1.text);
}
it doesnt work. I hope someone can help me!!!
Of course this does not work. As you call the Navigate method multiple times the Page MultiGameis loaded 2 times with each one of the parameters.
Why don`t you pack the two variables in one object array, and pass this to the navigate method?
Like
this.Frame.Navigate(typeof(MultiGame),new object[] {bg2.Source, txtBox1.text});
In the MultiGame class you now have to watch to the PageNavigated event. The navigation data is now your array.
In my current design approach I am running into a case where I'm having to perform an extra Database read and Databind on controls, only to overwrite them later on in the page lifecycle. The end result to the user is the same, but behind the scenes I'm doing two unnecessary and costly operations.
The search button is on the Master page. All the display controls (gridviews/tables/labels/etc) are on the content pages. The database call and databinding must be done in the Page_Init() method (most of the controls being used must be bound here).
When the user searches for an item, I save his search input in the session to persist it as being actively viewed across all the other content pages. So that when any content page is initialized, I check to see if they are actively viewing an item, and if so display his details.
// Master Page
protected void BtnSearch_OnClick(object sender, EventArgs e)
{
MySession.Current.ItemName = TxtItem.Text.Trim();
Server.Transfer("~/default.aspx");
}
// Content Page
protected void Page_Init(object sender, EventArgs e)
{
// If they're actively viewing an item, display its info
bool HasActiveItem = string.IsNullOrEmpty(MySession.Current.ItemName) ? false : true;
if (HasActiveItem)
{
// Makes one DB call to get all info;
// Binds all that info to GridViews/tables/labels on the page
BindAllDataControls(MySession.Current.ItemName);
// Display
DisplayItemDetails();
}
}
Here's the Issue: Say the user is currently viewing an Item = Boots. This value is saved in the session. Now the user searches for Item = Shirts and clicks the search button.
When the content page loads, he checks if there's anything in the session, there is but it's Item = Boots. It performs the unnecessary database/databind calls. Then, the BtnSearch click event triggers, we load the new Item = Shirts value into the session, and start the life cycle over. This lifecycle is good to go.
How can I get rid of that extra processing? Is the approach wrong?
I've thought about performing Page.IsPostback() and Page.IsCallback() logic during the content page initialization, but there are multiple other controls that cause postbacks and callbacks in the real web application. Therefore, I don't think I can get enough info from this to make the determination to skip or not. I've thought about wrapping the entire part of the page that contains all the GridViews/tables/labels/etc. in an ajax Callback, but I don't think that's a good approach. I've thought about sending an ajax call back to the server during the BtnSearch click that sets a flag. Then during load, we read that flag to skip or not, but there's no guarentee that that ajax call will process before the search BtnClick event.
Any ideas? Or should I just eat these extra calls and be done with it? There's got to be another way.
The most simple solution I see here is to make the check of search text change direct on PageInit and not on the button call.
// Master Page
protected void BtnSearch_OnClick(object sender, EventArgs e)
{
// remove that lines
// MySession.Current.ItemName = TxtItem.Text.Trim();
// Server.Transfer("~/default.aspx");
}
// Content Page
protected void Page_Init(object sender, EventArgs e)
{
// direct add here your variable on session
var vSearchText = TxtItem.Text.Trim();
if(!string.IsNullOrEmpty(vSearchText))
MySession.Current.ItemName = vSearchText ;
// ------------ rest of your code ---------------
// If they're actively viewing an item, display its info
bool HasActiveItem = string.IsNullOrEmpty(MySession.Current.ItemName) ? false : true;
if (HasActiveItem)
{
// Makes one DB call to get all info;
// Binds all that info to GridViews/tables/labels on the page
BindAllDataControls(MySession.Current.ItemName);
// Display
DisplayItemDetails();
}
}
Now to tell you the truth, the Server.Transfer is not good idea, what I do is that I use parameter in the URL, to include the search string from the input of the user, so when the user is add something for search I create the url as:
http://www.mydomain.com?q=test
and then I read the q and use it to fill the search box and make the search. This way you also have a SEO friendly search, the user can save his search and you avoid the server transfer that have other issues.
I am currently working on an app for WP7 for my university, and need a temporary solution to a problem. Now this solution is, that I will be loading a webpage using the web browser control for WP7. For example: http://m.iastate.edu/laundry/
Now as you see on the webpage, there are certain elements I want to hide, for example the back button. For now, what I have done to handle the back button is something like this:
private void webBrowser1_Navigating(object sender, NavigatingEventArgs e)
{
// Handle loading animations
// Handle what happens when the "back" button is pressed
Uri home = new Uri("http://m.iastate.edu/");
// The the current loading address is home
// Cancel the navigation, and go back to the
// apps home page.
if (e.Uri.Equals(home))
{
e.Cancel = true;
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
}
Now that works beautifully, except for the part that there is a back button on the hardware.
So my second option is to completely hide the back button ONLY on that page, and not its children. So not on http://m.iastate.edu/laundry/l/0
I am still debating on just parsing the data and displaying it in my own style, but I'm not sure if that's completely needed seeing how the data needs constant internet service and is already in a well-put format. Plus, I feel like that would be a waste of resources? Throw in your opinions on that too :)
Thanks!
You should inject a script in the page with InvokeScript.
Here is the kind of Javascript code you need to remove the back button:
// get the first child element of the header
var backButton = document.getElementsByTagName("header")[0].firstChild;
// check if it looks like a back button
if(backButton && backButton.innerText == "Back") {
// it looks like a back button, remove it
document.getElementsByTagName("header")[0].removeChild[backButton];
}
Call this script with InvokeScript:
webBrowser1.InvokeScript("eval", "(function() { "+ script +"}()");
Warning: IsScriptEnabled must be set to true on the web control
If the removal of the back button depends of the page, just test the navigating URI in C# and inject the script if neeeded.
I have a NavigationWindow (window1) and a custom navigationstate.
What I currently am using to do my navigation is as such:
a function (navigate(string,bool) ) which takes the location (a URL) that I want to go to, plus a boolean which defines if I should make a Back entry (i.e. I've gone into a folder)
A seperate function which ties into my NavigationService (allowing me to go back/forth within my history)
My problem though becomes that when I navigate Back, I start overriding my history!
Here's my NavigationService_Navigating(...) (which gets called when I push the back/forth button)
void NavigationService_Navigating(object sender, NavigatingCancelEventArgs e)
{
try // If something goes wrong, just bail.
{
// If we're going backwards, we want to remember the current location.
if (e.NavigationMode == NavigationMode.Back) { e.ContentStateToSave = new GopherNavState(cLocation); }
// use our internal navigation to move to the location, but dont create a back entry.
navigate((e.TargetContentState as GopherNavState).tLocation, false);
}
catch
{ } // ...
}
the problem occurs sporatically. I'll create 3/4 entries in my back, go back and see that my history is full of the page I'm currently looking at.
I've tried everything, but I still cant get it right.
I've found the source of my heartache: the history menu. Turns out, the fact I was using the chrome from the NavigationWindow was causing my headaches.
To fix this, I've simply turned off navigation controls within the window and made my own (buttons that have the command BrowseBack and BrowseForward).