【问题标题】:Hyperlink Visibility in MVVM and PrismMVVM 和 Prism 中的超链接可见性
【发布时间】:2017-06-07 05:30:42
【问题描述】:

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

有没有一种方法,我们可以设置超链接的可见性,而不是使用 TextBox 作为其内容?

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);
   }
} 

视图模型:

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

【问题讨论】:

    标签: c# xaml mvvm hyperlink prism


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2010-12-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-21
      • 2019-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多