【问题标题】:Unreachable code detected WP8检测到无法访问的代码 WP8
【发布时间】:2014-06-28 18:04:50
【问题描述】:

如果 IsDownloaded 为 True,此代码将不会继续。如果 False 和 Return;,我如何正确弹出 MessageBox?如果我拿出'Return;'即使 IsDownloaded 为 True,RingToneTask 也不会发生。

private void ExecuteSaveSoundAsRingtone(string soundPath)
    {
        if (IsDownloaded == false)
            MessageBox.Show("Will not download until you short press atleast once");
        return;
        App.Current.RootVisual.Dispatcher.BeginInvoke(() =>
        {

            SaveRingtoneTask task = new SaveRingtoneTask();
            task.Source = new Uri("isostore:/" + this.SavePath);
            task.DisplayName = this.Title;
            task.Show();
        }
           );

【问题讨论】:

  • 你问如何使用if-statement?在这种情况下,请从学习 C# 开始
  • 你的问题完全糊涂了。

标签: c# windows-phone-8 return messagebox


【解决方案1】:

使用范围

private void ExecuteSaveSoundAsRingtone(string soundPath)
{
    if (IsDownloaded == false)
    {
        MessageBox.Show("Will not download until you short press atleast once");
        return;
    }
    App.Current.RootVisual.Dispatcher.BeginInvoke(() =>
    {

        SaveRingtoneTask task = new SaveRingtoneTask();
        task.Source = new Uri("isostore:/" + this.SavePath);
        task.DisplayName = this.Title;
        task.Show();
    }
       );

【讨论】:

  • 也将 if (IsDownloaded == false) 替换为 if (!IsDownloaded) :-)
猜你喜欢
  • 2011-05-09
  • 2010-12-01
  • 1970-01-01
  • 2014-05-22
  • 1970-01-01
  • 1970-01-01
  • 2018-09-21
  • 2017-01-02
相关资源
最近更新 更多