views:

24

answers:

2

I am building a GPS-related application that displays the coordinates amongst other calculations. My demo code is setup to fire the events every second.

Whenever I update the main page UI (say, a textbox with the calculated Latitude), it works fine.

The problem is if I try to "flick" from one side to the other side, to change the page. While in the process of "flicking", if the textbox was to update, it jumps the main page back into view.

Kind of hard to explain in text without a video. But imagine click-n-holding, and draging the panoramic screen just a little - say, to peek at the next page but not flipping yet. Well, if the textbox was to update during that time, you'd loose your mouse-click-hold, and it would jump back to the main page.

Once you DO get to the next page, it stays and I can see the overflow updating from the previous page. No big deal there. But it's just trying to get to that next page.

I'm new to WP7/Silverlight, so I've been trying to use the Dispatcher to make things more responsive. No matter what I do (using the Dispatcher or not), this always happens. So, I am guessing this has to do with the UI being updated.

A little code always helps:

void GeoWatcher_PositionChanged(object sender,
    GeoPositionChangedEventArgs<GeoCoordinate> e)
{
    Deployment.Current.Dispatcher.BeginInvoke(() => MyPositionChanged(e));
}
void MyPositionChanged(GeoPositionChangedEventArgs<GeoCoordinate> e)
{
    var model = GeoProcessor.GetPosition(e.Position);

    latitude.Text = model.Latitude;
    longitude.Text = model.Longitude;
    altitude.Text = model.Altitude;
    accuracy.Text = model.Accuracy;
    direction.Text = model.Direction;
    speed.Text = model.Speed;
    speedAvg.Text = model.SpeedAvg;

}

When any of these textboxes are updated, the screen "jumps" back to the main page. Kind of a bad experience.

Maybe that is normal? Is there an event to hook into to knowing that the user is trying to "slide" to the next page?

Thanks in advance.

+1  A: 

Well, this feels like a hack. But I got the delay I wanted by hooking into some events. If there are other events I should be using (e.g. mousedown/mouseup), let me know. Again, this is a hack but works.

bool isChangingPage = false;
bool isCompleting = false;

public MainPage()
{
    InitializeComponent();
    this.Loaded += new RoutedEventHandler(MainPage_Loaded);

    this.ManipulationStarted += 
        new EventHandler<ManipulationStartedEventArgs>(MainPage_ManipulationStarted);
    this.ManipulationCompleted += 
        new EventHandler<ManipulationCompletedEventArgs>(MainPage_ManipulationCompleted);
}

void MainPage_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
{
    isChangingPage = true;
}

void MainPage_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
    if (isCompleting)
        return;
    isCompleting = true;

    Deployment.Current.Dispatcher.BeginInvoke(() =>
    {
        Thread.Sleep(1000);
        isChangingPage = false;
        isCompleting = false;
    });
}

All I have to do now is check the isChangingPage boolean in my code. And pass it to events, etc.

eduncan911
+1  A: 

I'd guess that when you set .Text on all those objects directly they are receiving focus (or something similar.)

Try using databinding to set the values.
I do this successfully to update the text of controls on PanoramaItems which are not in view.

Matt Lacey