I am trying to write canvas with children collection set with binding. It cannot be done like the others controls and there are many solutions over the internet how to do it in WPF, however none of them works for UWP App and it's limited possibilites.
What I have for now is ItemsControl overriden to have Canvas control instead of default StackPanel. Here is my code:
<ItemsControl x:Name="Railer" ItemsSource="{x:Bind ViewModel.ItemsToShowInCanvas, Mode=TwoWay, Converter={StaticResource OtoO}}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas x:Name="MyCanvas"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="v:SubPanelViewModel">
<Grid>
<v:SubPanelView Width="100" Height="{Binding ActualHeight, ElementName=MyCanvas}"
ManipulationDelta="TextBlock_ManipulationDelta" ManipulationMode="All"
ManipulationCompleted="SubPanelView_ManipulationCompleted"
/>
<Grid.RenderTransform>
<TranslateTransform X="{Binding Left, Mode=OneWay}" Y="{Binding Top, Mode=OneWay}"/>
</Grid.RenderTransform>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
SubPanelView is my custom control, datacontext for it is SubPanelViewModel containing Left, Top and ZIndex properties which I am binding to view. Using RenderTransform is hack to set my element where I want - the only way I've found trough searching the internet to have it positioned like with Canvas.Left/Top properties.
What I can't do is having the ZIndex property set correcly - no mattter what I try. The reason is because my items are not directly children of the Canvas. I just want to have the item brought up to front when I am manipulating it.
Should I just give up and do everything in code behind or is there any way to achieve what I want?