开发者

View visibility is not changing

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 _c开发者_开发技巧mdShowSearchResultsView 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?


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 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. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜