WPF:StackOverFlowException 迭代网格
情况是这样的:
我试图对我的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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只是猜测,但似乎
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 doingcurrentTB.IsChecked = true;
in your conditional statement which triggers the event to be called again and again....