0
votes

I have some experience in making Winform applications, but not in WPF.

My questions is about panels in WPF.

In Winform, say, I have two panels: PanelA and PanelB. I can place PanelB on top of PanelA by setting PanelB to visible and PanelA to hidden. By doing so, all the controls on PanelA are disabled, which means the controls are not visible to users and cannot be selected by hitting TAB.

However, in WPF, I cannot find an equivalent control to achieve the same effect. I have tried Rectangle, but the controls on the underneath Rectangle can still be selected if the users hit TAB.

I want something that can not only visually block the controls(buttons, etc.), but also preventing the users from selecting them by hitting TAB.

I know there is a way to do it by setting the IsEnabled property to false in WPF in order to disable the controls. But is there an easier way? Like the Panel control in Winform?

1
Set IsEnabled to false on the parent container to disable everything inside. - Lucas Trzesniewski
StackPanel, WrapPanel, and Grid serve that purpose. They all have an IsEnabled property which disables all children when false. We think about layout differently in XAML so you'll really need to read MSDN on each of those container controls. I've linked the MSDN pages for each. - 15ee8f99-57ff-4f92-890c-b56153
You can also play with the ZIndex while both panels are visible and enabled. Setting ZIndex to 1 on PanelA and ZIndex to 2 on PanelB will result in putting PanelB "above" PanelA. - Khalil Khalaf
Thank you guys for all the replies. It looks like I have to play with "IsEnabled" property and ZIndex then. :) - KaKaShi_CantAim
@KaKaShi_CantAim ZIndex isn't the best way to do this stuff. Use IsEnabled to enable/disable, and use the Visibility property to hide/show (along with either a valueconverter or a style trigger). - 15ee8f99-57ff-4f92-890c-b56153

1 Answers

0
votes

I don't know if it is easier than setting the IsEnabled property of the entire Panel to false but the second element you add to a Grid in WPF ends up on top of the first one. So if you want to hide and effectively disable a Rectangle, you could add it to a Grid and then add another element to the same Grid, e.g.:

<Grid>
    <Rectangle Width="100" Height="100" Fill="Green" />
    <!-- This child Grid that contains a Button element will effectively hide the above Rectange -->
    <Grid>
        <Button Content="On top..." />
    </Grid>
</Grid>