Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding element visibility to a ViewModel property, with design-time support

I've got a WPF application using Caliburn.Micro. I want to be able to overlay the application with a shadow and progress ring (from MahApps.Metro) when I want the application to wait for some work to be done in the background.

What I have at the moment actually works but the overlay is always-on at design time. My ShellView window looks like this:

<Window ...>
    ...
    <Grid>
        ...
        <Rectangle x:Name="waitShadow" Fill="#3f000000" Stroke="Black" StrokeThickness="0" Visibility="{Binding IsWaiting, Converter={StaticResource BooleanToVisibilityConverter}}" Grid.RowSpan="2"/>
        <ContentControl ... Visibility="{Binding IsWaiting, Converter={StaticResource BooleanToVisibilityConverter}}">
            <Controls:ProgressRing ...> <!-- from MahApps.Metro -->
            </Controls:ProgressRing>
        </ContentControl>
    </Grid>
</Window>

My ShellViewModel class has a public bool property IsWaiting and when I set it to true the shadow and ring comes up and everything is disabled. When I set it to false it goes back to normal, so the binding works (I'm using Fody with the PropertyChanged addin). The only problem is that the Visibility property isn't collapsed at design time.

Is there a better way to have an overlay that works at design time?

like image 331
Rebecca Scott Avatar asked Dec 26 '22 13:12

Rebecca Scott


1 Answers

You can set a FallbackValue on your binding, that will Collapse it in design time

Visibility="{Binding IsWaiting, Converter={StaticResource BooleanToVisibilityConverter}, FallbackValue=Collapsed}"

You could also make IsWaiting a DependancyProperty and set the default there, But I find this the easiest solution.

like image 165
sa_ddam213 Avatar answered Dec 29 '22 10:12

sa_ddam213