Set windows phone store application start up page instead of MainPage - c#

I am new to windows phone 8 development, I have MainPage.xaml which is start up page by Default, I have used this page as a login page, But every time I run my application it opens login page and need to put username and password, Instead of MainPage I want to set UserList.xanl as my start up page.
the next event is MainPage.xaml page_loaded event,
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/UserList.xaml", UriKind.Relative));
}
I dont want to use above code,
I have googled around but there was not any clue? Can anyone help me? Thanks

Did you try changing it in your WMAppManifest?
Reference: Setting The Start Page in Windows Phone 7 Application

You can change startup page in the app.xaml.cs file.
Find this method:
protected async override void OnLaunched(LaunchActivatedEventArgs e)
and change MainPage to UserList here:
if ( !rootFrame.Navigate( typeof(MainPage), e.Arguments ) )

Related

ASP.NET Change the current webform

I am working at a problem in ASP.NET.
I have to create 2 windows (i think that I need to make web forms, i don't know why they said windows) one is the login form, when i press ok and the username and password is ok, I need to
show my second window (webform)
How can I do that?
I tried to do
protected void Button1_Click(object sender, EventArgs e)
{
Form2 form = new Form2();
form.SetFocus("id");
}
But it gives me error
A form tag with runat=server must exist on the Page to use SetFocus() or the Focus property.
What should I do?
Am i right, I have to do separate webforms for thoose windows?
This is the picture from the problem that they provided
If you use webforms you can just use the following code to redirect to second form:
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Webform2.aspx");
}

Windows Phone 8 open new page programmatically

I've started WP 8 development recently. I know C# a bit but not much. BTW, I'm trying to open a page pragmatically, but app is crushing.
My code is here
NavigationService.Navigate(new Uri("/Dashboard.xaml", UriKind.Relative));
But I'm being confused because it's working when I'm placing the code above within button click event code block.
ERROR Detail An exception of type 'System.NullReferenceException'
occurred in TestProgram.DLL but was not handled in user code
If there is a handler for this exception, the program may be safely
continued.
I need your advice.
EDIT: Code Added
Credens MyCred = new Credens();
// Constructor
public MainPage()
{
InitializeComponent();
if (MyCred.ifExists("api_key"))
{
NavigationService.Navigate(new Uri("/Dashboard.xaml", UriKind.Relative));
}
}
You cannot use the NavigationService in the constructor. Put your code to the OnNavigatedTo event and it will not crash
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (MyCred.ifExists("api_key"))
{
NavigationService.Navigate(new Uri("/Dashboard.xaml", UriKind.Relative));
}
}
Did you follow this tutorial step by step ?
You code seem right. As you said, you should have something like this :
private void hyperlinkButton1_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/Dashboard.xaml", UriKind.Relative));
}
Does you page are on the same folder ? Did you check the path ? Does you page exist ? Can you boot in it ? If you add a break point on the NavigationService, where failed it ?
I think this documentation is pretty helpful.
Try calling Navigate() on the PhoneApplicationPage Loaded or OnNavigatedTo() events.

Windows Phone 8 SDK - WebBrowser Control - How to refresh page from code

How can I refresh the webbrowser control from the code behind?
I am using Windows 8 SDK & C#.
You can accomplish this by storing the most recent visited Url then when you need to refresh you just navigate to it.
private void browser_Navigated(object sender, NavigationEventArgs e) {
lastUri = e.Uri;
}
private void Refresh() {
browser.Navigate(lastUri);
}
You could do this via injecting JS into the page via the browser contr:
var js = "window.location.reload(true);";
Browser.InvokeScript("eval", js);
Would be this way;
Browser.Navigate(new Uri(Browser.Source.AbsoluteUri));

Win Phone 8 : Navigating Only One Time

I'm on windows phone 8 project. Doing it with xaml in visual studio.
I have 4 pivot items in this project.
I want to navigate the home page (my first pivot item) with
menu on bottom of phone;
<shell:ApplicationBarIconButton IconUri="Images/appbar_home.png" Text="Home" Click="ApplicationBarIconButton_Click_2"/>
and on click event i wrote this;
private void ApplicationBarIconButton_Click_2(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/MainPage.xaml?PivotMain.SelectedIndex = 0", UriKind.Relative));
}
When i run the program, it works nice, when i go other pivot items, and click that home button, it goes, but if i walk around again and click button, it doesnt work. Why ?
I need to solve this.
Thanks for the answers.
You are having this problem because you are doing it wrong.
NavigationService.Navigate is meant to navigate between XAML Files, not reload them. The phone doesn't like to reload the same page over and over.
What you want to do instead is set the current selected index to the first page.
Reference:http://msdn.microsoft.com/en-us/library/windowsphone/develop/microsoft.phone.controls.pivot(v=vs.105).aspx
It will look something like this
private void ApplicationBarIconButton_Click_2(object sender, EventArgs e)
{
PivotControlName.SelectedIndex = 0;
}

C#, Windows Phone 7, Using if-else statement to check which page is displayed

Now I'm developing a Windows Phone 7 app, my app has three buttons located at the applicaton bar. Here is the event handler for these three buttons:
//app bar page navigation
private void ApplicationBarIconButton_Click1(object sender, EventArgs e)
{
if(//check if the current displayed page is mainpage)
{
//do nothing
}
else
{
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.RelativeOrAbsolute));
}
}
private void ApplicationBarIconButton_Click2(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/Audios.xaml", UriKind.RelativeOrAbsolute));
}
private void ApplicationBarIconButton_Click3(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/Statistics.xaml", UriKind.RelativeOrAbsolute));
}
The button navigation works well except the first one (Button_Click1) because when I first access the main page and click the first button the app will automatically go back to app list.
So I want to use if-else statement to check which page is currently displayed and then decide whether to navigate or stay in the current page.
It looks like you are using the ApplicationBar like you would use a TabBar within iPhone (or similar in Android, Bada, etc too)
In WP7, the Metro style is typpically to use a Pivot or Panorama rather than a "Tab Bar" for this type of navigation.
If you do want to use the ApplicationBar like this:
then you can (the WP7 Marketplace will allow it) but users might feel it's not very Metro.
then you might want to consider disabling the appropriate button rather than just stubbing out the action.
then you can detect the currently shown page using CurrentSource on the NavigationService
Also, please do note that if you try to navigate from MainPage.xaml to the same url MainPage.xaml then you will see an exception - as I recall, the navigation service complains about url fragments not being supported.
Button click1 should be removed from the main page. It makes no sense to have that button there.
Other pages should use the back button to return to the main page. Otherwise you mess up your back stack.

Categories

Resources