简体   繁体   中英

Binding on a List<UserControl>

I got some binding issues...

Shapes is a list of customized UserControls, for example one of those UserControl can be an Ellipse with some specific properties. My goal is to loop on this list and show all the UserControls (it can be an Ellipse, or a Rectangle...) I just want to show the UserControl like if I would just prompt his XAML Content.

Here is my grid, i just don't know what to put in the DataTemplate, i tried some different things but nothing worked actually, hope some can help me :)

<Grid>
    <s:ScatterView ItemsSource="{Binding Shapes}">
        <s:ScatterView.ItemContainerStyle>
            <Style TargetType="s:ScatterViewItem">
                <Setter Property="Background" Value="Transparent"></Setter>
            </Style>
            </s:ScatterView.ItemContainerStyle>
            <s:ScatterView.ItemTemplate>
            <DataTemplate>
                <class:Shape ShapeItem="{Binding}" />
            </DataTemplate>
        </s:ScatterView.ItemTemplate>
    </s:ScatterView>
</Grid>

如comment.if所述,如果ShapeItem是UserControl,请尝试将其与Content Property绑定。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM