wpf - WPF 下划线绑定 (MVVM)
问题描述
有没有办法绑定下划线?我正在尝试实现以下目标:
我有VievModel
一个 bool 属性:
public bool HomeButtonUnderline { get; set; } = false;
然后我想在以下函数中控制这个属性:
public void Home() {
//CurrentPage = ApplicationPage.Home;
//HomeButtonForeground = new SolidColorBrush(Colors.White);
HomeButtonUnderline = true;
SettingsButtonUnderline = false;
}
然后我可以在 XAML 中使用这个控件:
<Button>
<TextBlock Command="{Binding HomeNavCommand}" Underline="{Binding HomeButtonUnderline}"/>
</Button>
问题是没有“下划线”属性,而是由“TextDecorations”处理:
<Button>
<TextBlock TextDecorations="Underline">
</Button>
那么有没有办法使用 MVVM 控制下划线,甚至不用它?
解决方案
您可以在 TextBlock 的样式中使用 DataTrigger:
<Button Command="{Binding HomeNavCommand}">
<TextBlock Text="Home">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding HomeButtonUnderline}" Value="True">
<Setter Property="TextDecorations" Value="Underline"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</Button>
推荐阅读
- spring - spring cloud gateway和eureka服务发现有什么区别?
- ios - Mac Catalyst 应用程序在其他 Mac 上崩溃,但从 Xcode 运行时可以工作
- coq - 如何证明coq中相同归纳的两个不同构造函数产生的项不相等?
- json - 使用 jolt 规范并将 json 转换为 json 数组
- xamarin.forms - 使用foreach在Master详细信息中的分隔符?
- oracle-apex - 大文件的 Oracle APEX apex_data_parser 执行时间爆炸式增长
- php - php:在array_filter() 值之间插入换行符...?
- java - Java:条件语句和关系运算符
- gruntjs - 用 grunt-browserify 打包
- python - 建立新连接失败,找不到满足要求的版本soupsieve Beautiful Soup