Question

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!

Was it helpful?

Solution

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

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