【发布时间】:2018-08-13 16:57:07
【问题描述】:
tl;dr 我有一个 DataGrid,我正在绑定行标题。但是,我无法让它与绑定上的 StringFormat 属性一起使用。
我有一个这样设置的 WPF DataGrid:
<DataGrid HeadersVisibility="All"
ItemsSource="{Binding Data}">
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="Header" Value="{Binding Lane, StringFormat=Lane {0:0}}"/>
</Style>
</DataGrid.RowStyle>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Value1}" Header="Value 1" />
<DataGridTextColumn Binding="{Binding Value2}" Header="Value 2" />
<DataGridTextColumn Binding="{Binding Value3}" Header="Value 3" />
<DataGridTextColumn Binding="{Binding Value4}" Header="Value 4" />
</DataGrid.Columns>
</DataGrid>
但无论我做什么,我都无法让StringFormat 属性在DataGridRow 标头上正常工作。它显示的只是我绑定的数字,而不是格式文本。但是,如果我将相同的格式字符串放在TextBlock 上,它会完美运行。
<TextBlock Text="{Binding Lane, StringFormat=Lane {0:0}}"/>
有谁知道为什么StringFormat 属性没有正确使用?有没有办法获得我想要的行为?
编辑:这就是 Lane 属性的样子。
public int Lane {
get { return lane; }
set {
lane = value;
NotifyPropertyChanged();
}
}
【问题讨论】:
-
您尝试过 StringFormat={} Lane {0:0} 吗?
-
@Marsh 也不起作用 :(
-
什么是
Lane? -
这是一个整数属性@NetMage
标签: c# wpf wpfdatagrid