开发者

WPF: StackOverFlowException iterating grid

This is the case:

I trying to do a extra format to my tooglesbuttons

private void PanelToggles_Checked(object sender, RoutedEventArgs e)
{
   ToggleButton currentTB = sender as ToggleButton;
    if (currentTB != null)
    {
        foreach (UIElement tb in GridToggles.Children)
     开发者_如何学编程   {
            MessageBox.Show(tb.GetType().ToString());
              (tb as ToggleButton).IsChecked = false;
        }
        currentTB.IsChecked=true;
        currentTB.FontWeight = FontWeights.Bold;
        //implementation
    }
}

It throws StackOverFlowException, some ideas?


Just a guess, but it seems like PanelToggles_Checked is an event called infinite times and the reason could be because you are doing currentTB.IsChecked = true; in your conditional statement which triggers the event to be called again and again....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜