How to disable a Grid (Panel) in XAML Metro app?

后端 未结 3 1489
攒了一身酷
攒了一身酷 2021-01-28 05:57

I want to emulate modal dialog in XAML Metro App.

So I was going to set .IsEnabled = false on all controls apart from the one which will pose as a modal dialog.

相关标签:
3条回答
  • 2021-01-28 06:50

    Unfortunately no one seems to know (except Mr Skakun who gave wrong answer and never bothered to revise it).

    Hence my solution (the simplest) is to make the element in question Hidden - I cant find any other ways to 'disable' a grid.

    If I wanted to disable it correctly I would have to write a recursive function to find all FrameworkElements in the grid children and set IsEnabled = false though.

    0 讨论(0)
  • 2021-01-28 06:54

    Sorry, I am a little late to the party...

    Here is how I created a modal popup - I used a popup dialog where the top and bottom portions are transparent so that anything behind it will show through. When the popup is opened, I set its size to cover the entire screen.

    The top and bottom portions of the popup also are set to autosize (height = *), so that they fill up the entire top and bottom of the screen. This prevents any input from going into the grid underneath.

    Here is a screen shot of my popup in Visual Studio: enter image description here

    The popup is a grid with 5 rows, 3 for the dialog itself and 2 for the transparent top and bottom.

    Here is how the popup looks in my app. Obviously the grid shows through the transparent top and bottom. Since the popup fills the entire screen, any input (keyboard or mouse) goes to it rather than the grid underneath, making the popup act like a modal dialog.

    Popup with grid underneath

    Be warned though that with this strategy, you have to handle these events:

    • Screen resizes (full screen, snapped view, filled view) - you need to resize the popup to fit within each of the view states
    • Screen rotation - again, you have to handle resizing here
    • Keyboard popup - you need to shift the popup up so that the onscreen keyboard does not interfere with it.
    0 讨论(0)
  • 2021-01-28 07:01

    Set IsHitTestVisible = false on the background content.

    Additionally you could set focus to something in your modal layer root and set TabNavigation to Cycle on the modal layer root to make sure that users can't tab/shift+tab out of it. Also make sure the modal layer is all hit test-solid - e.g. Transparent or has some other fill so users can't click through it.

    Also make sure no Popups show while your modal layer is visible.

    0 讨论(0)
提交回复
热议问题