2017-03-27 31 views
-3

我已经写了一条if语句,我已经在这里发布了一次,现在除了我有的颜色更改外,它正常工作。正在应用不同的变量,但没有发生颜色变化。我认为这也是非常简单的事情,我不抓住它。任何援助都会很大。我可以先让颜色发生变化,但是变量永远不会显示在文本块中。textblock forground color not if with if语句

if (e.CmsData.Skill.InQueueInRing > 0) 
{       
    Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { callsWaitingData.Text = e.CmsData.Skill.InQueueInRing.ToString(); })); 
    callsWaitingData.Foreground = new SolidColorBrush(Colors.Red); 
} 
else if (e.CmsData.Skill.AgentsAvailable > 0) 
{       
    Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { callsWaitingData.Text = e.CmsData.Skill.AgentsAvailable.ToString(); })); 
    callsWaitingData.Foreground = new SolidColorBrush(Colors.Green); 
} 
else 
{       
    callsWaitingData.Text = "0"; 
    callsWaitingData.Foreground = new SolidColorBrush(Colors.Yellow); 
} 
+2

您不应该在传递给'BeginInvoke'的动作中改变颜色吗? – juharr

+0

当我这样做时它仍然不起作用。相同的结果 – mcavanaugh418

+0

你是什么意思的_“我可以让颜色变化先发生,然后变量永远不会显示在文本块中。”_ - 你的意思是颜色变化确实发生,但文本没有更新? – PaulF

回答

0

以下是分辨率。我最初尝试过,但无论出于何种原因,它都没有奏效。当我再次尝试它时。抱歉,添麻烦了!

if (e.CmsData.Skill.InQueueInRing > 0) 
        { 
         Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { callsWaitingData.Text = e.CmsData.Skill.InQueueInRing.ToString(); 

          callsWaitingData.Foreground = new SolidColorBrush(Colors.Red); })); 

        } 
        else if (e.CmsData.Skill.AgentsAvailable > 0) 
        {       
         Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { callsWaitingData.Text = e.CmsData.Skill.AgentsAvailable.ToString(); 
          callsWaitingData.Foreground = new SolidColorBrush(Colors.Green);}));       
        } 
        else if(e.CmsData.Skill.AgentsAvailable == 0) 
        { 
         Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { callsWaitingData.Text = e.CmsData.Skill.AgentsAvailable.ToString(); 
          callsWaitingData.Foreground = new SolidColorBrush(Colors.Yellow); })); 

        }