我有一个持有2个视图的Shell。它们都使用相同的viewmodel,实际上shell也使用相同的viewmodel。我在shell中有2个按钮,可以改变2个视图的可见性。看来,即使命令正在触发,该值正在更改并且我已正确配置onpropertychanged,视图也不会刷新。我已经尝试从父shell和视图本身控制可见性。
这些是我的命令:
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
这些是CommandExecutes:
Private Sub ShowMinimalistSearchResultsViewExecute()
Me.IsMinimalistSearchResultsViewVisible = True
End Sub
Private Sub ShowSearchResultsViewExecute()
Me.IsMinimalistSearchResultsViewVisible = False
End Sub
这是visiblity布尔....
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
以下是视图的XAML ....
<local:MinimalistSearchResultsView Grid.Row="1"
Visibility="{Binding IsMinimalistSearchResultsViewVisible,Converter={StaticResource DebugConverter}}" />
目前我所要做的就是在发出命令时让这一个视图显示或消失。我正在使用调试转换器来验证可见性是否甚至试图改变;它不是。
为什么这不起作用?
答案 0 :(得分:1)
根据你对Jehof的评论......
当你说“然后返回它”时你是说它返回布尔值或可见性。如果您没有使用BooleanToVisibilityConverter,则应确保转换器正在执行将布尔值转换为Visibilty.Visible或Visibility.Hidden / Collapsed的逻辑。
如果您只是返回进入转换器的布尔值,那么我相信这将是一个大问题。
答案 1 :(得分:0)