Jordan
Jordan

Reputation: 9911

Set the attached property the items in the ItemsControl using my custom panel does not work in WPF

I've created a custom panel with which you can do the following:

<custom:Timeline>
    <Button custom:Timeline.PointInTime="6:30 PM" />
</custom:Timeline>

When I do this, it works wonderfully. However, when I do something like this (which is what I need to do):

<DataTemplate x:Key="TimelineItemTemplate">
    <Grid d:DesignWidth="169" custom:Timeline.PointInTime="{Binding NotifyTime}">

    </Grid>
</DataTemplate>

<ItemsControl Grid.RowSpan="2" ItemTemplate="{DynamicResource TimelineItemTemplate}" ItemsSource="{Binding Items}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <custom:Timeline/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
</ItemsControl>

the PointInTime attached property is not set on the controls in the InternalChildren collection:

protected override Size ArrangeOverride(Size a_arrangeBounds)
{
    foreach (UIElement uiChild in InternalChildren)
    {
        var pointInTime = GetPointInTime(uiChild);

        // Arranginess stuff
        // Timeline.PointInTimeProperty is not set on 'uiChild'. WTH?
    }

    return base.ArrangeOverride(a_arrangeBounds);
}

How do I fix this?

Upvotes: 2

Views: 767

Answers (1)

brunnerh
brunnerh

Reputation: 185072

ItemTemplates are inside a container, for ItemsControls that container is a ContentPresenter. In any case you probably want to bind the property in the ItemsControl.ItemContainerStyle which will set the property on the container.

Upvotes: 3

Related Questions