Item template for AnimatedStackPanel

Views for WPF Forum

Posted 8 years ago by Michael Haps
Avatar
Hello.

Why cant I generate a item template for the AnimatedStackPanel like this?


        <ListBox Name="_list"
                 ItemsSource="{Binding Path=MyList}"
                 >
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <views:AnimatedStackPanel Name="_aPanel"
                                              Orientation="Vertical"
                                              >
                        <TextBlock Text="{Binding Path=Description"/>
                    </views:AnimatedStackPanel>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
        </ListBox>

The designer throws an exception:
System.Reflection.TargetInvocationException
Exception has been thrown by the target of an invocation.

Comments (1)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Michael,

What you have is not valid and wouldn't work with the native WPF StackPanel either. The ItemsPanel can only contain the Panel, without any child elements. I think you are looking for the ItemTemplate property, so something like:
<ListBox Name="_list" ItemsSource="{Binding Path=MyList}">
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <views:AnimatedStackPanel Name="_aPanel" Orientation="Vertical" />
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Path=Description}" />
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>


Actipro Software Support

The latest build of this product (v2019.1 build 0683) was released 19 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.