1

1) Using MVVM Light, I have an xCeed datagrid which I only want visible only after the user has opened a file.

So I've created a boolean property in the ViewModel and use the booleantoVisibilityConverter to parse that property

<Window.Resources>
    <BooleanToVisibilityConverter x:Key="booleanToVisibilityConverter" />

So in the (lengthy so I'm cutting off the beginning it) xaml I put on the datagrid, I added this to the end:

Visibility="{Binding Path=FileOpened, Converter={StaticResource booleanToVisibilityConverter}}">

The moment I put that to use though, the grid disappears from the designtime view, which I do not want.

Checking to see if I'm in Design View inside the property's accessor doesn't seem to help.

    public bool FileOpened
    {
        get
        {
            if (IsInDesignMode)
                return true;

            return fileOpened;
        }

        set => fileOpened = value;
    }

EDIT: I've also tried to call RaisePropertyChanged on the mutator. Didn't expect it to help and, sure enough, it didn't.

JoeHz
  • 2,136
  • 1
  • 18
  • 29
  • Does your View "ask" for `FileOpened` ? If so, you could try to create your own BooleanToVisibilityConverter just to know if it's called properly. – Juan Carlos Rodriguez Oct 19 '18 at 11:17
  • Not per se. I only created the property because I wanted the design view to be smart enough to show me the grid even though the application starts with it not visible. If there's another way to pull that off, I'm happy to hear it. – JoeHz Oct 19 '18 at 11:25
  • You may try to set the *design time* DataContext to an instance of a class that returns true: https://stackoverflow.com/questions/51308281/not-controlled-exception-in-wpf-xaml-the-specified-conversion-is-not-valid/51308611#51308611 – mm8 Oct 19 '18 at 13:16
  • By "ask" I meant if `FileOpened` getter is called when you initialize the view. Put a breakpoint in your `FileOpened` property and check if it's called. – Juan Carlos Rodriguez Oct 19 '18 at 13:18
  • Ah yes. A breakpoint in the getter is hit when I debug. – JoeHz Oct 19 '18 at 23:56

0 Answers0