views:

49

answers:

2

I have a Shell holding 2 Views. They both use the same viewmodel, in fact the shell uses the same viewmodel as well. I have 2 buttons in the shell that are supposed to change the visibility of the the 2 views. It appears that even though the command is firing, that the value is being changed and that i have onpropertychanged configured correctly, the view is not being refreshed. I have tried controlling the visibility from the parent shell and from within the view itself.

These are my Commands:

Public ReadOnly Property ShowMinimalistSearchResultsView As ICommand
            Get
                If _cmdShowMinimalistSearchResultsView Is Nothing Then
                    _cmdShowMinimalistSearchResultsView = New RelayCommand(AddressOf ShowMinimalistSearchResultsViewExecute)

                End If
                Return _cmdShowMinimalistSearchResultsView

            End Get
        End Property

        Public ReadOnly Property ShowSearchResultsView As ICommand
            Get
                If _cmdShowSearchResultsView Is Nothing Then
                    _cmdShowSearchResultsView = New RelayCommand(AddressOf ShowSearchResultsViewExecute)
                End If
                Return _cmdShowSearchResultsView

            End Get
        End Property

These are the CommandExecutes:

Private Sub ShowMinimalistSearchResultsViewExecute()
    Me.IsMinimalistSearchResultsViewVisible = True
End Sub

Private Sub ShowSearchResultsViewExecute()
    Me.IsMinimalistSearchResultsViewVisible = False

End Sub

This is the visiblity Boolean....

Private _isminimalistsearchresultsviewvisible As Boolean
Public Property IsMinimalistSearchResultsViewVisible As Boolean
    Get
        Return _isminimalistsearchresultsviewvisible
    End Get
    Set(ByVal value As Boolean)
        _isminimalistsearchresultsviewvisible = value
        OnPropertyChanged("IsMinimalistSearchResultsViewVisible")
    End Set
End Property

Here is the XAML for the view....

<local:MinimalistSearchResultsView Grid.Row="1"
                                           Visibility="{Binding IsMinimalistSearchResultsViewVisible,Converter={StaticResource DebugConverter}}" />

Currently all i am trying to do is get this one view to show or disappear when i issue the commands. I am using the debug converter to verify whether the visibility is even trying to change; which its not.

Why isnt this working?

+1  A: 

Based on your comment to Jehof...

When you say "then returns it" are you saying it's returning the boolean, or a Visibility. If you're not using the BooleanToVisibilityConverter, you should make sure your converter is doing the logic to convert a boolean to a Visibilty.Visible or Visibility.Hidden/Collapsed.

If you're simply returning the boolean that comes into your converter, then I believe this will be a big problem.

Scott
i already went ahead and configured it for that after thinking about that too. However, the converter is only firing once at application startup. When I click the button that changes the bound boolean value the converter is not called.
ecathell
The DataContext of your <local:MinimalistSearchResultsView /> isn't changing or getting updated after the initial loading is it? It seems that for some reason or another, your binding is getting broken... could you be manually setting the Visibility Property elsewhere, thus removing your binding and using the set value instead?
Scott
A: 

Scott kindof was going in the right direction. It was a viewmodel instance problem. Even though all 3 are using the same viewmodel, i have the viewmodels declared inside of each base view(for easier reusability) well, in my shell for the views I am not assigning the datacontext of each child view to the shells viewmodel. Thus each view was using a different instance of the same view. Its something I have done before, and will hopefully remember in the future. :)

ecathell