无法在窗口电话8中设置辅助磁贴

时间:2014-09-12 09:57:59

标签: c# windows-phone-8 visual-studio-2013 windows-phone-8.1

我尝试通过链接http://www.geekchamp.com/articles/how-to-add-and-remove-secondary-tiles-in-windows-phone-apps为我的应用设置辅助磁贴。然后我可以设置固定到启动菜单的辅助磁贴,但问题是,当我按下pin应用程序栏按钮时,它就像这样打破了代码句柄异常

  // Code to execute on Unhandled Exceptions
        private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
        {
            if (Debugger.IsAttached)
            {
                // An unhandled exception has occurred; break into the debugger
                Debugger.Break();
            }
        }

在启动菜单中创建了辅助平铺,但是当我点击它时,它无法恢复到固定页面。

我怀疑固定页面上使用的某些数据取决于从上一页面发送的数据;因此,当它从开始菜单直接导航到它时,它没有足够的数据。我是对的吗?

这是我要将其固定到启动菜单的页面:

namespace App_Skin_Test_Final_.All_Files.Product_Files
{
    public partial class Product_Detail : PhoneApplicationPage
    {
        string pro_name;
        string pro_image;
        string pro_ingridient;
        //string pro_link;
        string pro_use;
        string pro_dryDesc1;
        string pro_dryDesc2;
        // ImageSource image;

        private readonly string SecondaryTileUriSource = "Source=SecondaryTile";

        public Product_Detail()
        {
            InitializeComponent();


            // =====================================   Add Search application bar   =====================================
            // Show application bar
            ApplicationBar = new ApplicationBar();
            ApplicationBar.Mode = ApplicationBarMode.Default;
            ApplicationBar.Opacity = 1.0;
            ApplicationBar.IsVisible = true;
            ApplicationBar.IsMenuEnabled = true;

            // Search Application bar
            ApplicationBarIconButton btnSearch = new ApplicationBarIconButton();
            btnSearch.IconUri = new Uri("/images/Icon Application Bars/Search.png", UriKind.Relative);
            btnSearch.Text = "Search";
            ApplicationBar.Buttons.Add(btnSearch);
            btnSearch.Click += btnSearch_Click;

            ApplicationBarIconButton btnPin = new ApplicationBarIconButton();
            btnPin.IconUri = new Uri("/images/Icon Application Bars/pin.png", UriKind.Relative);
            btnPin.Text = "Pin";
            ApplicationBar.Buttons.Add(btnPin);

            btnPin.Click += btnPin_Click;

        }

        void btnPin_Click(object sender, EventArgs e)
        {
          // secondary tile can be created only as the result
          // of user input in an application

            ShellTile tile = this.FindTile(SecondaryTileUriSource);
            if(tile==null)
            {
                //because the UI will navigate to Start
                //When a new secondary tile is created
                //only one secondary tile can be created at a time
                StandardTileData tileData = this.GetSecondaryTileData();

                MessageBox.Show("The SecondaryTileUriSource is " + SecondaryTileUriSource);

                //having a unique NavigationUri is necessary for distinguishing this tile
               string tileUri = string.Concat("/All Files/Product Files/Dry/Product Detail.xmal?", SecondaryTileUriSource);

             //   MessageBox.Show("the uri is " + tileUri);
               ShellTile.Create(new Uri(tileUri, UriKind.Relative), tileData);

            }
        }
        // function Search application bar
        private void btnSearch_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/All Files/Product Files/Search.xaml", UriKind.Relative));
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            // Check if the Secondar tile exists 

            ShellTile secondaryTile = this.FindTile(SecondaryTileUriSource);

            if (secondaryTile != null)
            {

         // *****************************************************      tile.Delete();
                MessageBox.Show("Secondary tile exist.");
            }



            if (NavigationContext.QueryString.TryGetValue("pro_name", out pro_name))
            {

            }
            if (NavigationContext.QueryString.TryGetValue("pro_image", out pro_image))
            {

            }
            txtbPro_Name.Text = pro_name;

            BitmapImage bm = PhoneApplicationService.Current.State["myimage"] as BitmapImage;
            img_Product.Source = bm;

            // Ingridient Text
            pro_ingridient = PhoneApplicationService.Current.State["ItemDryIngridient"] as string;
            txtb_ingridient.Text = pro_ingridient;
            // Find on Somaly store
            //pro_link = PhoneApplicationService.Current.State["ItemDryLink"] as String;
            //txtb_link = pro_link;


            // How to use product
            pro_use = PhoneApplicationService.Current.State["ItemDryUse"] as string;
            txtb_howToUse.Text = pro_use;

            // Description 1 and Description 2
            pro_dryDesc1 = PhoneApplicationService.Current.State["ItemDryDesc1"] as string;
            txtb_description1.Text = pro_dryDesc1;
            pro_dryDesc2 = PhoneApplicationService.Current.State["ItemDryDesc2"] as string;
            txtb_description2.Text = pro_dryDesc2;



            // txtb_ingridient.Text = pro_image;
            // image = getImage(pro_image);
            // MessageBox.Show(image);
            // img_Product.Source = image;



        }

        private ImageSource getImage(string img)
        {
            return new BitmapImage(new Uri(img, UriKind.Relative));
        }



        /*********************************************
         * Create a Secondary Tile for pin application
         *********************************************/

        private StandardTileData GetSecondaryTileData()
        {
            StandardTileData titleData = new StandardTileData
            {
                Title = "Secondary Tile",
                BackBackgroundImage = new Uri("/Images/Allures/Base/aba001.jpg", UriKind.Relative),
                Count = 5,
                BackTitle = "Secondary Tile",
                BackgroundImage = new Uri("", UriKind.Relative),
                BackContent = "WPG Add Remove Tile Sample"
            };
            return titleData;
        }
        private ShellTile FindTile(string partOfUri)
        {
            ShellTile shellTile = ShellTile.ActiveTiles.FirstOrDefault(
                title => title.NavigationUri.ToString().Contains(partOfUri));
            return shellTile;
        }




    }
}

我怎么能纠正它工作正常?或者我的应用程序中是否还有其他东西?

0 个答案:

没有答案