1.1 problems with LayoutUpdated not firing, maybe

Topics: Bugs
Jun 6, 2011 at 10:25 AM

We have been working with a patter to have a base view (below) which fires into the vm for the initial layoutupdated event fire after the view has been navigated to in WP7 (as per Microsoft's perf guidance)

We noticed that for some unknown reason with 1.1 that View_LayoutUpdated would intermittently (let's say every 10 page navs or so?) NOT fire. The view would be bound to view model and binding worked etc. but the event in the view class to trigger the initial work to be done would not fire.

I reverted back to CM 1.0 RTW and everything is working fine, it's only with CM 1.1 that i get this problem! I'm really struggling to see why this might be, i cannot understand why the frame event wouldn't fire and how this could relate to CM...

(Yes, i know about OnViewReady which has been added, but as it works off the loaded event it won't work with back button presses which don't fire Loaded, but do fire OnNavigatedTo.)

   public class AppViewBase : PhoneApplicationPage
        private bool _onNavigatedToCalled = false;
        #region Public Constructor

        public AppViewBase()
            LayoutUpdated += new EventHandler(View_LayoutUpdated);
            SupportedOrientations = SupportedPageOrientation.Portrait;


        protected override void OnNavigatedTo(NavigationEventArgs e)
            _onNavigatedToCalled = true;
            SystemTray.IsVisible = false;

        void View_LayoutUpdated(object sender, EventArgs e)
            if (_onNavigatedToCalled)

                _onNavigatedToCalled = false;

                Dispatcher.BeginInvoke(() =>
                    var vm = this.DataContext as IAfterLayoutFirstUpdated;
                    if (vm != null)

Jun 7, 2011 at 1:39 PM

If we made the Screen OnViewReady wire after the OnNavigatedTo event, would that fix things?

Jun 11, 2011 at 2:26 AM

Yep, that's exactly what needs to happen, as OnNavigatedTo is only thing guaranteed to run once each time the page is navigated to, Loaded does not always fire on back button press.

Jun 30, 2011 at 1:16 AM

I pushed some changes in 23d3d3b9a640  Can you check it ASAP and let me know if the behavior is now correct?

Jul 1, 2011 at 9:08 AM

am testing now....

Jul 1, 2011 at 9:31 AM

mmm, for me if i add this to my VM is fires when the view is being navigated away from, not to..  The view object is also null.

protected override void OnViewReady(object view)        {


// view is null and this fires when view is navigated away from.


Jul 1, 2011 at 11:15 AM

however, the original problem about layoutupdated not firing appears to have been resolved. 

Jul 1, 2011 at 12:57 PM

Ok. I've pushed another version. Try that one out.

Jul 2, 2011 at 8:50 AM

perfect! working as expected for me now, thanks heaps Rob:)