0
string word = "sos";
    Dictionary<string, string> Codes = new Dictionary<string, string>
        {
            {"a", ".-   "}, {"b", "-... "}, {"c", "-.-. "}, {"d", "-..  "}, 
            {"e", ".    "}, {"f", "..-. "}, {"g", "--.  "}, {"h", ".... "},
            {"i", "..   "}, {"j", ".--- "}, {"k", "-.-  "}, {"l", ".-.. "},
            {"m", "--   "}, {"n", "-.   "}, {"o", "---  "}, {"p", ".--. "}, 
            {"q", "--.- "}, {"r", ".-.  "}, {"s", "...  "}, {"t", "-    "}, 
            {"u", "..-  "}, {"v", "...- "}, {"w", ".--  "}, {"x", "-..- "}, 
            {"y", "-.-- "}, {"z", "--.. "}, {"0", "-----"}, {"1", ".----"}, 
            {"2", "..---"}, {"3", "...--"}, {"4", "....-"}, {"5", "....."}, 
            {"6", ".----"}, {"7", "..---"}, {"8", "...--"}, {"9", "....-"}    
        };



    async public void RunMorseCode()
    {


        foreach (char c in word.ToCharArray())
        {
            string rslt = Codes[c.ToString()].Trim();
            foreach (char c2 in rslt.ToCharArray())
            {
                if (c2 == '.')
                {

                    gridHalfFront.Opacity = 0;
                     await Task.Delay(100);


                }
                else if(c2 == '-')
                {

                    gridHalfFront.Opacity = 0;
                     await Task.Delay(1000);

                }
                gridHalfFront.Opacity = 1;

            }

        }
    }

之后变黑并停止工作,Windows Store App,知道吗?

4

3 回答 3

1

这个问题是合乎逻辑的。解决方案:

gridHalfFront.Opacity = 1;
await Task.Delay(1000);

您还可以使用 Blend 并使用动画和故事板等创建状态

于 2015-09-03T12:17:40.523 回答
0

我刚刚在适用于 Windows 8.1 和 Windows 10 的 Windows 应用商店应用程序中的 Visual Studio 2015RC 中检查了这一点。它在这两种情况下都有效,但你最好在代码中添加另一个 Task.Delay,否则闪烁效果将不可见 - 也许这是你认为什么是“变黑”?我建议你在最后添加另一行

gridHalfFront.Opacity = 1;

例如在这里添加

等待任务.延迟(100);

这使闪烁更明显,应用程序感觉更“响应”。

于 2015-07-13T08:18:12.347 回答
-1

尝试用Task.Delay()这个替换你的电话:

new System.Threading.ManualResetEvent(false).WaitOne(milliseconds);

显然,对于您Task.Delay()正在尝试做的事情来说,这并不是最棒的事情

于 2012-07-20T18:16:31.707 回答