How to force wpf window / update control of disabled items

I was pulling my hair out trying to figure out why the normal Dispatcher.Invoke command doesnโ€™t work to redraw my window, but now I think the problem is with the disabled content. I use the full Dotnet 4.0 infrastructure.

If i use

private void DoSomething()
{
  HandleBusyEnableDisable(false);
  DoSomethingThatKeepsItBusy();
  HandleBusyEnableDisable(true);
}

private void HandleBusyEnableDisable(bool enabling)
{
  Cursor = enabling ? Cursors.Arrow : Cursors.Wait; 
  CanvasFunctions.IsEnabled = enabling;
  CanvasRight.IsEnabled = enabling;
  CanvasRight.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Render, EmptyDelegate);

I see a cursor change, but the content does not seem to be disabled. If I add

CanvasRight.Opacity = enabling ? 1 : .5;

then I think it works, sometimes. Is there anything else I can do?
The performed task checks the data entered by the user, so it is much easier to run in the GUI stream. It shouldn't be that hard.

+3
2

, , .

, , , INotifyChanged enabled . / , Binding Framework , IsEnabled , AffectsRender, .

:

<Style TargetType="Grid">
  <Style.Triggers>
    <DataTrigger Property="IsEnabled" Value="False">
       <Setter Property="Opacity" Value="0.5" />
    </DataTrigger>
  </Style.Triggers>
</Style>
+1

, Visuals , . . , , .

0

Source: https://habr.com/ru/post/1768532/


All Articles