单击按钮时可以防止出现默认事件

时间:2016-01-03 18:17:49

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

我有按钮点击事件

class Symbol
  def to_upcase_str
    self.to_s.upcase
  end
end

[:a, :b, :c].map(&:to_upcase_str)

我将在此功能中更改按钮颜色,但是,按下按钮并且我无法更改颜色(按钮处于活动/按下状态)。

如何按javascript private void AnswerPressAction(object sender, RoutedEventArgs e) { Button button = (Button)sender; Button validButton = null; string buttonName = button.Name; button.Background = new SolidColorBrush(Colors.Yellow); System.Threading.Thread.Sleep(1000); int presedAnswer = 0; switch (buttonName) { case "buttonAnswer1": presedAnswer = 1; break; case "buttonAnswer2": presedAnswer = 2; break; case "buttonAnswer3": presedAnswer = 3; break; case "buttonAnswer4": presedAnswer = 4; break; } switch (_valid_answer) { case 1: validButton = buttonAnswer1; break; case 2: validButton = buttonAnswer2; break; case 3: validButton = buttonAnswer3; break; case 4: validButton = buttonAnswer4; break; } if (presedAnswer != 0 && presedAnswer == _valid_answer) { button.Background = new SolidColorBrush(Colors.Green); System.Threading.Thread.Sleep(1000); CreateQuestion(1); } else { button.Background = new SolidColorBrush(Colors.Red); validButton.Background = new SolidColorBrush(Colors.Green); System.Threading.Thread.Sleep(1000); _gameLevel = 0; } } ,或在按钮按下之前运行此事件,当按钮未激活时?

1 个答案:

答案 0 :(得分:2)

问题在于您使用$Country = $config_xml.selectnodes('/root/Countries/Country[@Name = "USA"]/MyFilters/child::node()') 调用阻止该线程。如果您想引入延迟,请查看Task.Delay method。您需要了解一些Sleep方法(MSDN上的大量示例,或者您可以搜索SO)。

async延迟期间,您很可能需要禁用UI,因为延迟允许UI继续更新(并显示您想要的颜色更改),但它也允许用户与UI(例如,第二次单击按钮,或单击其他按钮)。 await属性在这里会有所帮助。