Question

I am working on a program to manage a minecraft server with a local UI as well as a remote interface. I have a button on a ribbon bar that will enable or disable the remote interface and a textbox for inputting the port. Currently, I disable the textbox when the networking is enabled, but, disabling does not re-enable the textbox after I set it to true again (and setting a breakpoint reveals it to still be 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();
    }

Thank you for any help resolving why the textbox will not enable again.

Was it helpful?

Solution

Old Question but i kept coming across it while searching for an answer so figured i'd post an answer anyways. There is a bug in the ribbonTextbox control that results in isenabled always being false if there is no command associated. There are 2 ways round this from what i have found:

1: Create a new control based on the ribbontextbox and override the isenabledcore property to always return true. As shown here Cannot set RibbonTextBox isEnable to False

2: Create a dummy command and associate it with the control

public static readonly ICommand DummyCommand = new RoutedCommand("Dummy", typeof(Control));
    public static void Dummy(Object sender, ExecutedRoutedEventArgs e)
    {
        // Do nothing its a dummy command
    }
    public static void CanDummy(object sender, CanExecuteRoutedEventArgs e)
    {
        e.CanExecute = true;
    } 

as described in a comment in this link http://blogs.msdn.com/b/wpf/archive/2010/10/21/wpf-ribbon-october-2010-update-details.aspx . AS i said probably no help to the original poster but i kept coming across it while looking for an answer so it may save someone else a few minutes of googling time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top