none
在通过文件进入程序时报 远程调试失效 这个是什么意思有人清楚么? RRS feed

答案

  • 你好 AndyLiu,

    通过文件进入程序?你指的是OnFileActivated method 这个嘛?

    可能是你代码的问题,你能把你的代码贴出来让我看看么?

    我之前做了一个程序,也是使用OnFileActived方法,也遇到这样的问题,我把正确的代码贴出来给你看看:

    App.xaml.cs

            protected override void OnFileActivated(FileActivatedEventArgs e)
            {
                Frame rootFrame = Window.Current.Content as Frame;
                if (rootFrame == null)
                {
                    rootFrame = new Frame();
                    Window.Current.Content = rootFrame;
                }
    
                if (rootFrame.Content == null)
                {
                    if (!rootFrame.Navigate(typeof(MainPage)))
                    {
                        throw new Exception("Failed to create initial page");
                    }
                }
    
                var page = rootFrame.Content as MainPage;
                if (page != null)
                {
                    page.FileEvent = e;
                }
    
                // Ensure the current window is active
                Window.Current.Activate();
            }

    mainpage.xaml.cs

            public FileActivatedEventArgs _fileEventArgs = null;
            public FileActivatedEventArgs FileEvent
            {
                get { return _fileEventArgs; }
                set { _fileEventArgs = value; }
            }
    
            public async void Page_Loaded(object sender, RoutedEventArgs e)
            {
                try
                {
                    var fileList =  await _fileEventArgs.NeighboringFilesQuery.GetFilesAsync();
                    foreach (StorageFile file in fileList)
                    {
                        IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read);
                        BitmapImage bitmapImage = new BitmapImage();
                        bitmapImage.SetSource(fileStream);
                        Image displayImage = new Image();
                        displayImage.Source = bitmapImage;
                        imagegallery.Items.Add(displayImage);
                    }
                }
                catch (Exception k)
                {
                    txt.Text = "需要通过右键图片选择以ImageGallery打开的方式来运行程序。";
                }
            }

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2014年8月13日 2:18
    版主