So I have a big Grid where I work with coordinates with margin.
Now I have a List with Icons (Images) that should be displayed at specific coordinates.
I use a ItemsControl with an DataTemplate with an Image in it to Display them.
My Problem is now that if I spawn the first Image, it is on the right spot but if I spawn now the next one, it will get displayed on the right X coordinate, but every time with an space between the first and the next one.
So my Question is: How can I display a List of Images, that gets bigger in runtime, with margin coordinates in my bigger Grid element?
(And I dont want columns etc.)
Code for better understanding:
<Grid Width="4045" Height="2823">
<ItemsControl Width="4045" Height="2823" ItemsSource="{Binding AllPoI, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" VerticalAlignment="Top" >
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type poi:PointOfInterest}">
<Image Margin="{Binding MarginCoordinates}" Height="16" Width="16" HorizontalAlignment="Left" VerticalAlignment="Top" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
Try with the comment from Clemens (This Works perfect, this is the Answere):
<Grid Width="4045" Height="2823">
<ItemsControl Width="4045" Height="2823" ItemsSource="{Binding AllPoI, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" VerticalAlignment="Top" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Canvas.Left" Value="{Binding PosX}"/>
<Setter Property="Canvas.Top" Value="{Binding PosY}"/>
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type poi:PointOfInterest}">
<Image Height="16" Width="16"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
//This Canvas below gets the same coordinates as the newest Entry on my List. this Canvas is displayed on the correct Position, the list entry not.
<Canvas Height="{Binding Gridsize, UpdateSourceTrigger=PropertyChanged}" Width="{Binding Gridsize, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" Margin="{Binding GridSelectorPosition}" VerticalAlignment="Top" Visibility="{Binding GridSelectorVisibility, Converter={StaticResource VisibleWhenBoolIsTrueConverter}}">
<Rectangle Stroke="Red" Fill="Red" Opacity=".3" Width="{Binding Gridsize, UpdateSourceTrigger=PropertyChanged}" Height="{Binding Gridsize, UpdateSourceTrigger=PropertyChanged}"/>
</Canvas>
</Grid>