我正在开发一个程序来管理具有本地 UI 和远程界面的 minecraft 服务器。我在功能区栏上有一个按钮,可以启用或禁用远程接口和一个用于输入端口的文本框。目前,我在启用网络时禁用了文本框,但是,在我再次将其设置为 true 后,禁用并不会重新启用文本框(并且设置断点显示它仍然为 false)。
private void NetToggleChecked(object sender, RoutedEventArgs e) {
portTextBox.IsEnabled = false;
if (ButtonPressedByUser) {
var result = MessageBox.Show("Are you sure you want to enable networking with the current settings?" +
" If not properly configured, it may be possible for an attacker to enter your server.",
"Simple Bukkit Wrapper", MessageBoxButton.YesNo, MessageBoxImage.Warning,
MessageBoxResult.No);
if (result == MessageBoxResult.No) {
ButtonPressedByUser = false;
NetworkToggle.IsChecked = false;
ButtonPressedByUser = true;
return;
}
}
Config.NetConf["enabled"] = "true";
int port;
if (!int.TryParse(Config.NetConf["port"], out port)) {
MessageBox.Show("Port could not be parsed (is it a number?)");
ButtonPressedByUser = false;
NetworkToggle.IsChecked = false;
ButtonPressedByUser = true;
return;
}
Net.Listener.StartListening(port);
}
private void NetworkToggleUnchecked(object sender, RoutedEventArgs e) {
portTextBox.IsEnabled = true;
if (ButtonPressedByUser) {
var result =
MessageBox.Show("Are you sure you wish to disable all networking to your server? It will " +
"be impossible to connect to it remotely and any existing connections will be closed.",
"", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
if (result == MessageBoxResult.No) {
ButtonPressedByUser = false;
NetworkToggle.IsChecked = true;
ButtonPressedByUser = true;
return;
}
}
Config.NetConf["enabled"] = "false";
Net.Listener.StopListening();
}
感谢您帮助解决文本框无法再次启用的原因。