This is a question with many different answers, but have not found one working for Windows Phone.
So here goes:
I have an Items Control that displays UserControls.
I bind an ObservableCollection to this ItemsControl like this:
<Canvas Name="CanvasGrid" Grid.Column="1" Background="Transparent" Canvas.ZIndex="5">
<ItemsControl ItemsSource="{Binding InGame}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Canvas>
<View:SInGame/>
</Canvas>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Canvas>
When an element is added in Itemscontrol the element is given a zindex independent of what I give the element, and the usercontrol which is showed. What I want to do is have to buttons where I can move the selected element up and down in the z direction.
View SInGame
The Canvas inside the itemscontrol is needed for the position to be binded correctly from the following view:
<UserControl x:Class="MVVMTestApp.View.SInGame"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WP8"
xmlns:View="clr-namespace:MVVMTestApp.View"
mc:Ignorable="d"
Canvas.Left="{Binding pos.x}" Canvas.Top="{Binding pos.y}">
<Path >
<.....
....../>
</Path>
</UserControl>
It could then be argued that the view should consist of a Canvas that has the position binded. But this would still leave the issue of the zindex.
As stated in the comments. The ItemsControl
cannot see the outside canvas and can therefore not use the zindex to reach that. So how is it possible to set the zindex? Or is it not possible using the ItemsControl
element?