WPF DataTriger 用法示例代码

Posted 碎心炼心

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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>

 

以上是关于WPF DataTriger 用法示例代码的主要内容,如果未能解决你的问题,请参考以下文章

从控制台应用程序启动 WPF 窗口

Xcode中的变量模板(variable template)的用法

c_cpp 加载源图像固定用法(代码片段,不全)

WPF 高性能位图渲染 WriteableBitmap 及其高性能用法示例

需要示例代码片段帮助

c_cpp kstat_lookup和kstat_read用法的示例kstat片段