简单的问题是:当绑定命令 .CanExecute 返回 false 时,如何隐藏超链接?
xml:
<TextBlock>
<Hyperlink Command="{Binding IncludesCanExecuteCommand}">Link text</Hyperlink>
</TextBlock>
编码:
...
private ICommand _includesCanExecuteCommand;
....
_includesCanExecuteCommand = new RelayCommand(ExecuteTheCommand, CanExecuteTheCommand);
....
public ICommand IncludesCanExecuteCommand
{
get
{
return _includesCanExecuteCommand;
}
}
....
public bool CanExecuteTheCommand()
{
return BooleanResult();
}
public void ExecuteTheCommand()
{
DoSomeWork();
}
如何设置文本块/超链接(或运行,如果需要)的样式,以便在 CanExecute() 函数返回 false 时链接折叠?我试过了:
<Hyperlink.Style>
<Style TargetType="{x:Type Hyperlink}" BasedOn="{StaticResource DefaultHyperlinkStyle}">
<Setter Property="TextBlock.Visibility" Value="Visible" />
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="TextBlock.Visibility" Value="Collapsed" />
</Trigger>
</Style.Triggers>
</Style>
</Hyperlink.Style>
我还尝试将样式放在文本块上(无法访问超链接)和超链接内的 Run(没有可见性属性)。
感谢所有想法!