Reputation: 95
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>
</Grid.Column>
</TextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
But don't work. I'm sure that the converter work well...
Upvotes: 1
Views: 2383
Reputation: 184296
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>
Upvotes: 4