Transition between phone pages - c#

I'm developing a Windows Phone application.
Is there anyway to animate transition between phone pages?
Now, I'm using this to navigate between pages:
NavigationService.Navigate(new Uri("/Views/SelectComponent.xaml", UriKind.Relative));
Thanks.

What you could do is have a "Page1Out" storyboard and "Page2In" storyboard. Then, assign a Completed event handler to the storyboard like this:
Page1Out.Completed += new EventHandler(Page1Out_Completed);
Then handle that event
void Page1Out_Completed(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/Views/SelectComponent.xaml", UriKind.Relative));
}
This will play your out transition and then load the new page. In the new page, you want to do something similar, but handle it in the OnNavigatedTo() event.
Hope that helps

The same question with answers can be found here

Related

Set windows phone store application start up page instead of MainPage

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 ) )

Refresh current page in wp8,

I'm try to refresh current page but not able to do this. Basically I used user control and inherit to another user control. Button click event is working properly. But not refresh the page.
Page = (Application.Current.RootVisual as Frame).Content as Page;
string u = Convert.ToString(Page.NavigationService.CurrentSource);
Page.NavigationService.Navigate(new Uri(u, UriKind.Relative));
The Problem here is you can't use navigation in UserControl, It must be from Page.
So, in your user control create an event handler like this..
public event EventHandler Refresh;
Now, in your page make its Handle as..
MyUserControl.Refresh += UserControl_Refresh;
void MyUserControl_Refresh(object sender, EventArgs e)
{
//refresh logic here
}
Then in your UserControl invoke this Event where ever required as
Refresh.Invoke(this, null);
And it will work.
just enter your desired page there on any event you wish it will refresh the page
NavigationService.Navigate(new Uri("/pagetorefresh.xaml", UriKind.Relative));
Did you try removing the BackStack?
NavigationService.RemoveBackEntry();
How to reload a Windows phone application page without creating a new copy in the memory?
navigating to same page in windows phone 8
When you want to Navigate to a Page from UserControl, you have to do like this
(Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/ProjectName;component/Pages/SignatureCapturePage.xaml", UriKind.Relative));
And when you want to Navigate to a new instance of a page(in which you are residing), you need to append a new GUID
(Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/ProjectName;component/Pages/SignatureCapturePage.xaml?id="+Guid.NewGuid().ToString(), UriKind.Relative));
But your ultimate purpose it to refresh the page and not to navigate to a new page, so you can either trigger a event in the page from your UserControl or go for DataBinding.
DataBinding is the best approach and you can get notified using INotifyPropertyChanged when some changes happens with the Usercontrol. See DataBinding for Windows Phone 8

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 phone7: Open a webpage on button click?

I just searched, but didn't find a way to create a web link in my Windows phone7 Application. In Android TextView has android:autoLink='Web' In Windows phone7 textblock I didn't find any relevant property.
Tried adding the NavigateURI property in the Hyperlink and it gives an exception. NavigateUri="http://www.google.com"
Really appreciate If someone Can suggest How to do this. Thanks in Advance...!!!!!
Use just the HyperLinkButton Control.
And add this property to your control:
<HyperlinkButton TargetName="_blank" Content="Go To" Click="HyperlinkButton_Click"/>
Finally add the click event handler to launch the browser using the BrowserTask :
private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
{
WebBrowserTask webBrowserTask = new WebBrowserTask();
webBrowserTask.Uri = new Uri("http://www.google.com");
webBrowserTask.Show();
}

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