How to handle whitespace in DataTrigger binding for WPF DataGrid?

为君一笑 提交于 2020-01-06 02:36:45

问题


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>

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.


回答1:


Good question!

You can use single quote on the property name.

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


来源:https://stackoverflow.com/questions/24734954/how-to-handle-whitespace-in-datatrigger-binding-for-wpf-datagrid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!