我在WPF中为DisplayMemberBinding
设置了GridViewColumn
。
<GridViewColumn Header="{x:Static resx:TextResources.ExcutionTimesHeaderErrorType}" DisplayMemberBinding="{Binding Exception, Mode=OneWay, Converter={StaticResource typeConverter}, FallbackValue='---'}"/>
typeConverter
&#39;模仿&#39; Exception.GetType()
扩展名,在Gui中将异常类型显示为字符串。如果没有异常且该值为null,我想在此列中输出另一个属性。现在我想对PriorityBinding
使用DisplayMemberBinding
,但GridViewColumn
除了PriorityBinding
以外都没有作为&#39;子元素&#39;,也不可能将DisplayMemberBinding
属性用作&#39;子元素&#39;。有没有办法PriorityBinding
使用GridViewColumn
这样的方式:
<GridViewColumn Header="{x:Static resx:TextResources.ExcutionTimesHeaderErrorType}">
<PriorityBinding>
<Binding Path="Exception" Mode="OneWay" Converter="{StaticResource typeConverter}" IsAsync="True" />
<Binding Path="AnotherProperty" IsAsync="True" />
</PriorityBinding>
</GridViewColumn>
修改
我将我的代码更改为&#34; ASh&#34;下面,但它不起作用:
<GridViewColumn Header="{x:Static resx:TextResources.ExcutionTimesHeaderErrorType}">
<GridViewColumn.DisplayMemberBinding>
<PriorityBinding FallbackValue="-*-">
<Binding Path="Exception" Converter="{StaticResource typeConverter}" Mode="OneWay" IsAsync="True"/>
<Binding Path="Comment" FallbackValue="---"/>
</PriorityBinding>
</GridViewColumn.DisplayMemberBinding>
</GridViewColumn>
如果Exception
属性为null,则显示值为空。我检查了第二个绑定属性&#34;评论&#34;设置好了。
这两个绑定正常工作:
<GridViewColumn Header="{x:Static resx:TextResources.ExcutionTimesHeaderComment}" DisplayMemberBinding="{Binding Comment, FallbackValue='---'}"/>
<GridViewColumn Header="test2" DisplayMemberBinding="{Binding Exception, Mode=OneWay, Converter={StaticResource typeConverter}, FallbackValue='---'}"/>
答案 0 :(得分:1)
您缺少<GridViewColumn.DisplayMemberBinding>
代码:
<GridViewColumn>
<GridViewColumn.DisplayMemberBinding>
<PriorityBinding>
<Binding Path="Exception" Mode="OneWay" Converter="{StaticResource typeConverter}" IsAsync="True" />
<Binding Path="AnotherProperty" IsAsync="True" />
</PriorityBinding>
</GridViewColumn.DisplayMemberBinding>
</GridViewColumn>
GridViewColumn标有ContentProperty属性,内容属性为标题:[ContentProperty("Header")]
。因此,<GridViewColumn>
标记没有GridViewColumn.
前缀的内部内容应该分配给标题属性