MVVM 和 Prism 中的超链接可见性

Hyperlink Visibility in MVVM and Prism

我有一个用于注销的超链接,它应该隐藏在主页上,因为用户尚未登录。只要用户登录,它就应该可见。 我已经将超链接中的文本替换为文本框,并在检查身份验证后设置其内容。

有没有一种方法可以设置超链接的可见性,而不是使用文本框来显示其内容?

XAML代码:

<TextBlock DockPanel.Dock="Right" TextAlignment="Center" Margin="0,0,0,10" Width="60">
        <Hyperlink Name="lnkLogOut" Focusable="True" FontSize="16" FontStyle="Normal" Command="{Binding LogOutCommand}" Foreground="#AC0000">
            <TextBlock Text="{Binding LogOutText}" />
            <!--Log Out--> // this was the static text before
        </Hyperlink>
        </TextBlock>

型号:

private string _showlogOut = string.Empty;   
public string ShowlogOut
{
   get { return _showlogOut; }
   set
   {
       SetProperty(ref _showlogOut, value);
   }
} 

ViewModel:

if (_isLoginSuccessful)
{
   ShowlogOut = "Log Out"; 
//.............other code...............
}

视图模型中的另一个 (bool) 属性 使用 BoolToVisibilityConverter 绑定到注销超链接的可见性,或者创建一个 StringEmptyToVisibilityConverter 并使用现有的 属性.