WPF:StackOverFlowException 迭代网格

发布于 2024-10-10 18:26:12 字数 575 浏览 7 评论 0原文

情况是这样的:

我试图对我的toglesbuttons 进行额外的格式,

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
    }
}

它会抛出 StackOverFlowException,有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何以心动 2024-10-17 18:26:12

只是猜测,但似乎 PanelToggles_Checked 是一个名为无限次的事件,原因可能是因为您在触发的条件语句中执行 currentTB.IsChecked = true;该事件将被一次又一次地调用......

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....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文