Enabling a specific button inside a disabled grid
Asked Answered
M

1

6

I got a button inside a grid that contains many other buttons and controls such as this

<Grid IsEnabled="false">
    <Grid.ColumnsDefinition>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
    </Grid.ColumnsDefinition>
    <Button Content="Run"/>
    <Button Grid.Column="1" Content="Test"/>
    <Button Grid.Column="2" Content="Cancel" IsEnabled="true"/>
</Grid>

As you can see the grid is disabled, but the cancel button inside it is supposed to be enabled.

The problem I'm having is that even though I set the inside button to be enabled, it stays disabled, probably because its parent is disabled.

Is there any way to override this behavior and force the button to be enabled?

I'm using it for a case where there's a long process running in the background, so all the UI actions except for cancelling the process should be disabled.

Thanks!

Masson answered 30/4, 2012 at 6:36 Comment(0)
M
4

No. Setting IsEnabled property to false leads to disabling all the nested visual elements. One should think of element's contents as parts of its being. Disabling the element means disabling all of its parts.

The easiest workaround is to change the markup to meet your needs. I would rather bring the Cancel button out of this Grid so it's never affected by IsEnabled property of the Grid

Metabolize answered 30/4, 2012 at 6:54 Comment(4)
The code sample I brought here is just a simple version of a much more complex UI structure I have. I know your solution would work, but it would mean that I would have handle the enabling and disabling of many other sibling controls which would be a big overhead for a simple request. I wonder if maybe there's another solution. Thanks!Masson
@Masson Did you find any solution for this problem ?Leeann
Sorry, almost 10 years have passed since then. I don't recall if/how this was resolved.Masson
I have a feeling it was by going through the tedious path EvAlex mentioned.Masson

© 2022 - 2024 — McMap. All rights reserved.