Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I would like to arrange items of a collection in a grid with a specific number of columns and rows (say 4x6). Each item exposes the dependency properties (integer) X and Y and should be placed in the relevant cell of the grid. Note that the collection can change during runtime which should update the grid items.

I couldn't find any good solution. But maybe it is even possible without using the code-behind?

Don't mind conversion or something. This stuff changes anyway. The used collection class isn't important. (You can choose one.)

How can I solve this problem? Any appropriate suggestions would we welcome, thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.0k views
Welcome To Ask or Share your Answers For Others

1 Answer

<ItemsControl ItemsSource="{Binding YourItems}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <Grid/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemContainerStyle>
        <Style>
            <Setter Property="Grid.Column" Value="{Binding X}"/>
            <Setter Property="Grid.Row" Value="{Binding Y}"/>
        </Style>
    </ItemsControl.ItemContainerStyle>
</ItemsControl>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...