Свойство WPF Bind Grid.Column - PullRequest
1 голос
/ 24 марта 2011

Мне нужно установить свойство 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>

Но не работай. Я уверен, что конвертер работает хорошо ...

1 Ответ

4 голосов
/ 24 марта 2011

Ваш 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>
...