WPF Bind Grid.Column Property
I need to set Grid.Column property of an item by a converter. this is my xaml :
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Periodo.Inizio}">
<Grid.Column>
<MultiBinding Converter="{StaticResource ItemColumnSetter}">
<Binding RelativeSource="{RelativeSource Self}" />
<Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=local:Timeline}" Path="StartDate" />
<Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=local:Timeline}" Path="EndDate" />
<Binding Path="Periodo.Inizio" />
</MultiBinding>
</Gr开发者_运维知识库id.Column>
</TextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
But don't work. I'm sure that the converter work well...
Your TextBlock will be wrapped in another control of some sort, that means any Grid.XXX
properties will be disregarded. To apply those properly you need to do the binding in the ItemsControl.ItemContainerStyle
.
Should be something like this:
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Grid.Column">
<Setter.Value>
<MultiBinding Converter="{StaticResource ItemColumnSetter}">
<Binding RelativeSource="{RelativeSource Self}" />
<Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=local:Timeline}" Path="StartDate" />
<Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=local:Timeline}" Path="EndDate" />
<Binding Path="Periodo.Inizio" />
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
</ItemsControl.ItemContainerStyle>
精彩评论