Reputation: 2287
I have set a DisplayMemberBinding
for a GridViewColumn
in WPF.
<GridViewColumn Header="{x:Static resx:TextResources.ExcutionTimesHeaderErrorType}" DisplayMemberBinding="{Binding Exception, Mode=OneWay, Converter={StaticResource typeConverter}, FallbackValue='---'}"/>
The typeConverter
'imitates' the Exception.GetType()
extension to show the type of the exception as string in the Gui. In case there is no exception and this value is null I want to output another property in this column. Now I want to use PriorityBinding
as for the DisplayMemberBinding
, but neither GridViewColumn
does except PriorityBinding
as a 'sub-element', nor is it possible to use the DisplayMemberBinding
attribute as 'sub-element'. Is there a way of using PriorityBinding
for a GridViewColumn
like this:
<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>
EDIT
I changed my code to the suggestion of "ASh" below, but it does not work:
<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>
The display value is empty, if the Exception
property is null. I checked if the second binding property "comment" is set and it is.
These two bindings work properly:
<GridViewColumn Header="{x:Static resx:TextResources.ExcutionTimesHeaderComment}" DisplayMemberBinding="{Binding Comment, FallbackValue='---'}"/>
<GridViewColumn Header="test2" DisplayMemberBinding="{Binding Exception, Mode=OneWay, Converter={StaticResource typeConverter}, FallbackValue='---'}"/>
Upvotes: 0
Views: 818
Reputation: 35713
you are missing <GridViewColumn.DisplayMemberBinding>
tag:
<GridViewColumn>
<GridViewColumn.DisplayMemberBinding>
<PriorityBinding>
<Binding Path="Exception" Mode="OneWay" Converter="{StaticResource typeConverter}" IsAsync="True" />
<Binding Path="AnotherProperty" IsAsync="True" />
</PriorityBinding>
</GridViewColumn.DisplayMemberBinding>
</GridViewColumn>
GridViewColumn is marked with ContentProperty attribute and content property is Header: [ContentProperty("Header")]
. So the inner content of <GridViewColumn>
tag without GridViewColumn.
prefix should be assigned to Header property
Upvotes: 1