automatic redirection after specific time in WP8 - windows-phone

I'm developing windows phone 8 application.
I have two pages ; one of the page is the start up one ; Once the user open the application this page will appear and automatically after a specific time ; it will redirect the user to the main menu of the application .
How I can make an automatic redirection after specific time in WP8 ?

May be these lines of code helps you:
public partial class MainPage : PhoneApplicationPage
{
private DispatcherTimer timer;
// Constructor
public MainPage()
{
InitializeComponent();
timer = new DispatcherTimer();
//Set your specific time here using TimeSpan instance
timer.Interval = TimeSpan.FromSeconds(2);
timer.Tick += (s, e) => {
var frame = App.Current.RootVisual as PhoneApplicationFrame;
frame.Navigate(new Uri("/Page1.xaml", UriKind.Relative));
};
timer.Start();
}
}
Hope it helps.

Look at this answer for the a timer implementation. Only thing left to do is, when the timer finished, call a navigation method to navigate to the main menu.

Related

Adding a page before the hub page in a Windows Phone 8.1 store app

I'm building a Windows Universal Store App, concentrating first on the Windows Phone 8.1 app. I'm basing my app on a hub app. I want to add a splash page to the app startup to replace the static splash screen with a XAML based animation. I am confused by navigation since it all seems to be set up and owned by the hub page.
I have looked at
Mike Taulty's blog post about Windows/Phone 8.1–Frame, Page, NavigationHelper, SuspensionManager;
Quickstart: Navigating between pages;
How to extend the splash screen; and
Navigation Patterns
In fact the last of those explicitly states that "hub pages are the user's entry point to the app".
How do I add pages to my hub app that the user will encounter before the hub, like a splash page or a logon screen?
Typically no sooner had I posted the question than I saw where to find the answer. When NavigationHelper is added to the project along with the hub page it includes comments explaining how to use it:
To make use of NavigationHelper, follow these two steps or
start with a BasicPage or any other Page item template other than BlankPage.
1) Create an instance of the NavigationHelper somewhere such as in the
constructor for the page and register a callback for the LoadState and
SaveState events.
public MyPage()
{
this.InitializeComponent();
var navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += navigationHelper_LoadState;
this.navigationHelper.SaveState += navigationHelper_SaveState;
}
private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
}
private async void navigationHelper_SaveState(object sender, LoadStateEventArgs e)
{
}
2) Register the page to call into the NavigationHelper whenever the page participates
in navigation by overriding the Windows.UI.Xaml.Controls.Page.OnNavigatedTo
and Windows.UI.Xaml.Controls.Page.OnNavigatedFrom events.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
navigationHelper.OnNavigatedTo(e);
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
navigationHelper.OnNavigatedFrom(e);
}
That boiler-plate code only required slight changes in my page: take out the async, and make navigationHelper an instance variable.
Then to start in another page follow the instructions in Set start page in Windows Phone 8.1 universal app to edit App.xaml.cs thus:
#if WINDOWS_PHONE_APP
if (!rootFrame.Navigate(typeof(SplashPage), e.Arguments))
{
throw new Exception("Failed to create initial page");
}
#endif
#if WINDOWS_APP
if (!rootFrame.Navigate(typeof(HubPage), e.Arguments))
{
throw new Exception("Failed to create initial page");
}
#endif
Then in SplashPage.xaml.cs when I need to navigate to the hub page I add
if (rootFrame.Navigate(typeof(HubPage)))
{
Window.Current.Content = rootFrame;
}
else
{
throw new Exception("Failed to create hub page");
}

Enable - Disable a button while threading vsto for ms word

I'am very new to threading and quite unclear as to why this is happening in my code, when I click on a button that verifies hyperlinks in my document, I start a new thread that does the verification once it starts I want to disable the ribbon button and enable it again after thread finished but this is not happening and I dont know what is the mistake .Here is what I have tried so far:
public class Alpha :Ribbon1
{
// This method that will be called when the thread is started
public void Beta()
{
foreach() { //do something } after this loop ,enable the button again
button.enable=true //not applying
} }
private void button_Click(object sender, RibbonControlEventArgs e)
{
Alpha oAlpha = new Alpha();
// Create the thread object, passing in the Alpha.Beta method
Thread oThread = new Thread(new ThreadStart(oAlpha.Beta));
// MessageBox.Show("Please wait till the document is checked for invalid links");
// Start the thread
oThread.Start();
button7.Label = "Pls wait";
button7.Enabled = false;
}
Ribbon needs to be rendered again after enable/disable for change to take effect, you can do this by calling IRibbonUI.Invalidate()

MvvmCross and back button in Windows Phone app

I'm building a Windows Phone app (8.1 using WinRT) using MvvmCross. To navigate to a new view I using ShowViewModel(). But when I hit the back button on the phone the app is closing instead of navigating back to the first view. How can I do it I want to return to the first view when I hitting the back button?
I solved it to use a interface in my viewmodel with a backbutton event, then I wrote a client speific implementation of it. In the viewmodel I handle the event and called the close method in the my base class MvxViewModel. Read more about my solution on my blog, http://danielhindrikes.se/windows-phone/handle-windows-phone-back-button-pressed-when-using-mvvm/
Here's a simpler solution. Create a base type for all your WP pages that derives from MvxWindowsPage. Then, handle the back key there and route the proper information to your VM:
public abstract class MyBaseView : MvxWindowsPage {
public MyBaseView() {
this.InitializeComponent();
HardwareButtons.BackPressed += HardwareButtons_BackPressed;
}
void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e) {
if (Frame.CanGoBack) {
var vm = ViewModel as MyBaseViewModel;
if (vm != null) {
e.Handled = true;
vm.GoBackCommand.Execute(null);
}
}
}
}
Now, you also have to make sure that you have a base viewmodel which derives from MvxViewModel and from which you derive all your VMs. That base VM should have a GoBackCommand observable property, and executing that command should do a simple Close(this).
To see what's going on under the hood, see this related question: Windows Phone 8.1 Universal App terminates on navigating back from second page?
EDIT
Fixed declaration.

How to rotate windows forms in every 20 secs using timer in windows application?

I have four windows forms namely, form1.vb, form2.vb, form3.vb, form4.vb.
And also i have one master page namely form5.vb. So i have rotate one by one above four windows forms in form5.vb with every 20 secs . how to do it ?
On a 20 second timer you can call 'BringToFront' on each form.
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.bringtofront.aspx
Basically, you create a timer and call the function BringToFront on each form.
In C#:
static int counter = 1;
static void StartRotating()
{
System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
myTimer.Interval = 20000; // 20 seconds
myTimer.Tick += new EventHandler(TimerEventProcessor);
myTimer.Start();
}
private static void TimerEventProcessor(Object myObject,
EventArgs myEventArgs) {
// you could use a switch statement also
if(counter==1) form1.BringToFront();
if(counter==2) form2.BringToFront();
if(counter==3) form3.BringToFront();
if(counter==4) {
form4.BringToFront();
counter=0; //reset counter
}
counter++;
}
You need to keep an index to know which form is currently displayed and then in the timer elapsed event you can do this
formtoshow.TopMost = true;
formtoshow.BringToFront();

Animation not starting until UI updates or touch event

I have a strange problem with an AlphaAnimation. It is supposed to run repeatedly when an AsyncTask handler is called.
However, the first time the handler is called in the Activity, the animation won't start unless I touch the screen or if the UI is updated (by pressing the phone's menu button for example).
The strange part is that once the animation has run at least once, it will start without problem if the handler is called again.
Here's what the code looks like:
// AsyncTask handler
public void onNetworkEvent()
{
this.runOnUiThread(new Runnable() {
#Override
public void run()
{
flashScreen(Animation.INFINITE);
}
});
}
// Called method
private void flashScreen(int repeatCount)
{
final View flashView = this.findViewById(R.id.mainMenuFlashView);
AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
alphaAnimation.setRepeatCount(repeatCount);
alphaAnimation.setRepeatMode(Animation.RESTART);
alphaAnimation.setDuration(300);
alphaAnimation.setInterpolator(new DecelerateInterpolator());
alphaAnimation.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation)
{
flashView.setVisibility(View.VISIBLE);
}
#Override
public void onAnimationEnd(Animation animation)
{
flashView.setVisibility(View.GONE);
}
#Override
public void onAnimationRepeat(Animation animation) { }
});
flashView.startAnimation(alphaAnimation);
}
I have noticed that runOnUIThread isn't necessary (same results occur if I don't use it), but I prefer keeping it as I'm not on the UI thread.
Any ideas on what could cause this?
A little more research showed that my problem was the same a this question:
Layout animation not working on first run
The flashView's visibility was set to GONE by default (causing the Animation not to start immediately as the View had never been rendered), so I just need to set it to INVISIBLE before calling flashView.startAnimation()
If setting the View to VISIBLE won't work, as was in my case, it helped for me to call requestLayout() before starting the Animation, like so:
Animation an = new Animation() {
...
view.requestLayout();
view.startAnimation(an);
In my case, my View was 0dip high which prevented onAnimationStart from being called, this helped me around that problem.
This worked for me:
view.setVisibility(View.VISIBLE);
view.startAnimation(animation);
I had to set the view to VISIBLE (not INVISIBLE, neither GONE), causing the view renderization needed to animate it.
That's not an easy one. Till you got a real answer : The animation start is triggered by onNetworkEvent. As we don't know the rest of the code, you should look there, try to change onNetworkEvent by an other event that you can easily identify, just to debug if the rest of the code is ok or if it's just the trigger that is responsible for it.
May be it will help someone, because previous answers not helped me.
My animation was changing height of view (from 0 to it's real height and back) on click - expand and collapse animations.
Nothing worked until i added listener and set visibility to GONE, when animation ends:
collapseAnim.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
view.setVisibility(View.GONE);
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
And when expand just set it to VISIBLE before animation:
view.setVisibility(View.VISIBLE);
view.startAnimation(expandAnim);