WPF DataTriger 用法示例代码
用法1:
<DataGridTemplateColumn Header="{lex:LocText ExamineRoom}"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Name="tb" Text="{Binding ExamineRoom}"> </TextBlock> <DataTemplate.Triggers> <DataTrigger Value="False"> <DataTrigger.Binding> <MultiBinding Converter="{StaticResource OnlineRoomCoverter}"> <Binding Path="DataContext.OnlineRooms" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=DataGrid}" /> <Binding Path="ExamineRoom" /> </MultiBinding> </DataTrigger.Binding> <Setter TargetName="tb" Property="Foreground" Value="Red" /> <Setter TargetName="tb" Property="ToolTip" Value="{lex:LocText RoomNotOnline}" /> </DataTrigger> </DataTemplate.Triggers> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn>
用法2:
<DataGridTemplateColumn Header="{lex:LocText ExamineRoom}"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Name="tb" Text="{Binding ExamineRoom}"> <TextBlock.Style> <Style TargetType="TextBlock"> <Style.Triggers> <DataTrigger Value="False"> <DataTrigger.Binding> <MultiBinding Converter="{StaticResource OnlineRoomCoverter}"> <Binding Path="DataContext.OnlineRooms" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=DataGrid}" /> <Binding Path="ExamineRoom" /> </MultiBinding> </DataTrigger.Binding> <Setter Property="Foreground" Value="Red" /> <Setter Property="ToolTip" Value="{lex:LocText RoomNotOnline}" /> </DataTrigger> </Style.Triggers> </Style> </TextBlock.Style> </TextBlock> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn>
作者:碎心炼心
出处:http://www.cnblogs.com/karl-F
本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步