0

I develop app with setting page include Pivot. On NavigatedTo method, load data from db async and add PivotItem.

BUT, BackPressed event does not fire for N times tap on back button (N = count of dynamic add PivotItem) and after it event call correctly. when i comment dynamic add PivotItem code, BackPressed event work properly.

    protected override void OnNavigatedTo(Windows.UI.Xaml.Navigation.NavigationEventArgs e)
    {            
        HardwareButtons.BackPressed += HardwareButtons_BackPressed;

            DataService.GetDataFromDB().ContinueWith(data =>
            {
                RunOnUiThread(() =>
                {
                    data.Result.ForEach(item =>
                    {
                        var uc = new FolderUC(item);
                        var pivotItem = new PivotItem() { Header = item.Title, Content = uc };
                        pivot.Items.Add(pivotItem);
                    });
                });
            });
    }

What is wrong????

Hamid
  • 1,099
  • 3
  • 22
  • 37
  • What do you mean by 'BackPressed event does not fire N times (N = count of dynamic add PivotItem)'? You subscribe one in *OnNavigatedTo*, how does it suppose to run N times? – Romasz Jan 02 '15 at 11:16
  • means when i do it, and tap on back button, my event not fire. for example must tap 6 times on back button, and at 7th tap, back button event fire!! sorry for my bad english – Hamid Jan 03 '15 at 10:37
  • Check maybe you are subscribing to back button multiple times. Debuf your program and see. – Romasz Jan 03 '15 at 10:58
  • I already debug and see all thing is ok, as i say, when remove code that add PivotItem, all thing work fine. – Hamid Jan 03 '15 at 11:10
  • Subscribing to back key in OnNavigated to is not a good idea, you can navigate to your page multiple times and the vent is app wide. Have you tried to move it elswere and test? – Romasz Jan 03 '15 at 11:21
  • thanks for reply. it's good, because i remove event handler on OnNavigateFrom. also i test it at page constructor. same issue! – Hamid Jan 03 '15 at 14:15
  • Depending on your progrma, it may not be good - in some cases OnNavigatedTo may not be called. Nevertheless check if your program subscribes somewhere to back pressed and sets e.handeled to true. – Romasz Jan 03 '15 at 18:31

0 Answers0