Search code examples
c#mvvmwindows-phone-8expression-blend

How to disable all the controls on windows phone by displaying a semi transparent control over the page?


I'd like to have some sort of semi transparent/translucent effect displayed over the entire page and then display my option buttons on top of it but I just can't figure out how and it's driving me nuts! I've seen it in plenty of wp8 apps so it is doable but I just don't know how!

Once this semi transparent/translucent effect is displayed, I want it to dissapeared if clicked on or if one of my option buttons is clicked, and restore the screen as it was or execute an action accordingly.

I've somehow managed to do it by setting the Background colors using a storyboard but strangely enough, once displayed and my options buttons appear, they look fine but once the storyboard is completed, the button then look disabled as well which just looks wrong!!

What is the proper way to give a "Disabled" effect as if you had a semi transparent dialog box displayed over a window.

Any ideas, suggestions or code would be appreciated.

Thanks.


Solution

  • You may be making this more complicated than it needs to be. Consider the following XAML for example:

    <Grid x:Name="LayoutRoot">
      <Grid.RowDefinitions>
        <RowDefinition Height="*" />
      </Grid.RowDefinitions>
    
      <Grid x:Name="ContentRoot">
        ...
      </Grid>
    
      <Grid x:Name="ContentOverlay" Background="#AA000000" Visibility="Collapsed">
        ...
      </Grid>
    </Grid>
    

    Both ContentRoot and ContentOverlay will anchor at the top left of the LayoutRoot grid and span the row height. They will stack from furthest to closest in order of declaration, so ContentRoot will be rendered beneath ContentOverlay. Simply manipulate the Visibility of ContentOverlay based on user input.

    Alternatively, you can set the Opacity for ContentOverlay to 0 along with collapsed visibility (required so it doesn't intercept hits to the ContentRoot child controls below) and fade it in and out using storyboarding in Blend. That probably looks like a slightly cleaner transition to a user, even if it's only 0.3 seconds long or so.