WPF GridView:多次设置 属性 'Header'

WPF GridView: The property 'Header' is set more than once

我收到此编译器错误,但我认为我没有指定 header 两次。

代码如下:

<GridViewColumn Header="Margin" Width="180" ctrls:SortableListView.SortPropertyName="Margin">
    <Binding Path="Margin" Converter="{StaticResource currencyStringConverter}" ConverterParameter="#0.00"></Binding>
</GridViewColumn>

我正在尝试绑定到列值,而不是列 header。这总是 'Margin'.

我尝试了几种变体,例如:

<GridViewColumn Width="180" ctrls:SortableListView.SortPropertyName="Margin">
    <Binding Path="Margin" Converter="{StaticResource currencyStringConverter}" ConverterParameter="#0.00"></Binding>
    <GridViewColumnHeader Content="Margin"></GridViewColumnHeader>
</GridViewColumn>

但都产生相同的结果。

我做错了什么?

尝试以下代码:

<GridViewColumn Header="Margin" 
DisplayMemberBinding="{Binding Path=Margin, Converter={StaticResource currencyStringConverter} , ConverterParameter='#0.00'}" 
ctrls:SortableListView.SortPropertyName="Margin"/>

来自msdn

[LocalizabilityAttribute(LocalizationCategory.None, Readability = Readability.Unreadable)]
[ContentPropertyAttribute("Header")]
[StyleTypedPropertyAttribute(Property = "HeaderContainerStyle", StyleTargetType = typeof(GridViewColumnHeader))]
public class GridViewColumn : DependencyObject, 
    INotifyPropertyChanged

Content 这个 object 的 属性 是 Header 所以你不能这样做:

<GridViewColumn Header="Margin" ...>
    <Binding ...
</GridViewColumn>

因为在这种情况下你设置了两次 header。