如何处理WPF DataGrid的DataTrigger绑定中的空格? [英] How to handle whitespace in DataTrigger binding for WPF DataGrid?

查看:260
本文介绍了如何处理WPF DataGrid的DataTrigger绑定中的空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用自动生成datagrid并将其绑定到一个DataTable.This DataTable有一些空格像'Last Value'的列。现在我需要添加一个datatrigger来应用一些样式,如下所示:

I am using autogenerating datagrid and binding it to a DataTable.This DataTable has columns with whitespaces like 'Last Value'. Now I need to add a datatrigger to apply some style as shown below:

<DataGrid.Resources>                        
                    <Style x:Key="DgStyle" TargetType="{x:Type TextBlock}">
                        <Setter Property="TextAlignment" Value="Right"/>
                        <Style.Triggers>                               
                            <DataTrigger Binding="{Binding Last Value, Converter= {StaticResource DecimalToBoolConverter}}" Value="True">
                                <Setter Property="Foreground" Value="Red" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
        </DataGrid.Resources>

但是DataTrigger绑定不支持空格(最后值)。当我删除空格(LastValue),那么它工作正常。但是根据我的要求,我需要在datatable列名称的空格,这个表正在用于绑定datagrid。

But DataTrigger Binding doesn't support whitespaces (Last Value). When I remove the whitespace(LastValue) then it works fine. But as per my requirement I need whitespace in the datatable columns name and this table is being used to bind datagrid.

我如何处理这种情况?
请建议。

How could I handle this scenario? Please suggest.

推荐答案

好问题!

您可以在属性名称上使用单引号。

You can use single quote on the property name.

Binding={Binding 'Last Value', Converter= {StaticResource DecimalToBoolConverter}}"

这篇关于如何处理WPF DataGrid的DataTrigger绑定中的空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆