我需要通过转换器设置项目的Grid.Column属性。 这是我的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>
但是不要工作。 我确信转换器运行良好......
答案 0 :(得分:4)
您的TextBlock将被包装在某种控件中,这意味着任何Grid.XXX
属性都将被忽略。要正确应用这些,您需要在ItemsControl.ItemContainerStyle
。
应该是这样的:
<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>