如果我正确理解您的情况,您可以使用以下方法:
WindowsUIButton checkButton = new WindowsUIButton()
{
Caption = "Check Button",
Style = ButtonStyle.CheckButton
};
checkButton.CheckedChanged += checkButton_CheckedChanged;
tileContainer1.Buttons.Add(checkButton);
//...
int reentranceCount = 0;
void checkButton_CheckedChanged(object sender, EventArgs e) {
if(reentranceCount > 0) return;
/*do some stuff */
Uncheck((WindowsUIButton)sender);
}
void Uncheck(WindowsUIButton button) {
reentranceCount++;
try {
button.Checked = false;
}
finally { reentranceCount--; }
}
更新:
如果您使用TileContiner.ButtonChecked事件,您应该更新上面的代码,如下所示:
//...
tileContainer1.ButtonChecked += tileContainer_ButtonChecked;
//...
void tileContainer_ButtonChecked(object sender, ButtonEventArgs e) {
if(reentranceCount > 0) return;
/*do some stuff */
Uncheck((WindowsUIButton)e.Button);
}