问题
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