how to use panorama item selectionchanged

前端 未结 6 1780
情书的邮戳
情书的邮戳 2021-01-28 03:16

I am attempting to detect the current panorama item that a user is currently on and then toggle an application bar icon button isenabled property accordingly. I have not had any

6条回答
  •  再見小時候
    2021-01-28 03:31

    Testing using the header name is a bad idea, since your code will break if you rename your panorama item headers, or localize them.

    You could work out the selected index, but that would break if you re-ordered your items:

            PanoramaItem selectedItem = (PanoramaItem)e.AddedItems[0];
            int selectedIndex = mainPanorama.Items.IndexOf(selectedItem);
    

    The most robust way would be to set a Tag on your Panorama Items and test for that:

    XAML:

       
    
            
            
    
            
            
        
    

    Code behind:

        private void Panorama_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count < 1) return;
            if (!(e.AddedItems[0] is PanoramaItem)) return;
    
            PanoramaItem selectedItem = (PanoramaItem)e.AddedItems[0];
    
            string strTag = (string)selectedItem.Tag;
            if (strTag.Equals("places"))
                // Do places stuff
            else if (strTag.Equals("routes"))
                // Do routes stuff
    
         }
    

提交回复
热议问题