0

I have 10 buttons in my UI, when I press one of them, I need to disable the rest; but here is the tricky part :

I have a background thread running under a while loop for real time update. the background thread update UI (the 10 buttons state and other stuff), the thing is once I click all buttons are disabled (good), but the refresh stops working on buttons (they stay disabled).

Why do I need to disable buttons knowing that they are going to change state after a second? because synchronising data is not very efficient, there is a 0.5s gap (to get data from DB and update UI) and in that 0.5s, a user can press some buttons that he is not supposed to press.

<Button  Name="FirstGo" Width="60" Content="{StaticResource ButtonText_Go}" Click="FirstGoButtonClick" IsEnabled="{Binding First.JobLight,Converter={StaticResource JobLight2ButtonConv}}"/>

 private void FirstGoButtonClick(object sender, RoutedEventArgs e)
        {
            FirstStop.IsEnabled = false;

            SecondGo.IsEnabled = false;
            SecondStop.IsEnabled = false;

           //..... disabeling the other 6

           //doing some stuff  
           ViewModel.RunFirstJob();
        }
Abbas
  • 3,872
  • 6
  • 36
  • 63
  • You are disabling all the buttons in the `FirstGoButtonClick` event but where are you enabling them all again? – SWilko Jun 10 '16 at 09:16
  • I have a converter binded with a property "First.JobLight", this property gets updated by my background thread and tells the button in witch state he should be : IsEnabled="{Binding First.JobLight,Converter={StaticResource JobLight2ButtonConv}} the idea is, if i click a button then --> disable all buttons until the refresh happens and reset them to intial state. is it clear now ? – Sami Errougui Jun 10 '16 at 09:17
  • `First.JobLight` needs to implement `INotifyPropertyChanged` and the value needs to change for the converter to run. If you work out where `JobLight` changes you may find your problem – SWilko Jun 10 '16 at 09:21
  • JobLight does implement INotifyPropertyChanged, and it works fine without the disabling part, meening buttons reacte perfectly to refresh – Sami Errougui Jun 10 '16 at 09:22

1 Answers1

1
 FirstStop.IsEnabled = false;

This code removes the binding, so, the succeeding update value to JobLight won't be recognized by the framework.

What you can do is to use SetCurrentValue.

Or put the collection of buttons into a Selector and handle the JobLight property when SelectionChanged happen.

Community
  • 1
  • 1
tgpdyk
  • 1,203
  • 9
  • 13