這是一個有很多不同答案的問題,但還沒有找到一個適用於Windows Phone的問題。
所以這裏去:更改項目控件窗口中元素的zindex手機
我有一個項目控件,顯示UserControls。
我一個ObservableCollection綁定到此ItemsControl的是這樣的:
<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>
當元件被在ItemsControl中添加給出的是我給元件的Z-索引獨立的元件,並且其顯示出該用戶控件。我想要做的是必須按鈕,我可以在z方向上上下移動選定的元素。
查看SInGame
需要ItemsControl的內部畫布上的位置,以正確地從下面的視圖來綁定:
<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>
它可能然後可以說,認爲應包括的具有綁定位置的畫布。但是這仍然會導致zindex的問題。
正如評論中所述。 ItemsControl
無法看到外部畫布,因此不能使用zindex來達到此目的。那麼如何設置zindex?或者是否不可能使用ItemsControl
元素?
刪除ItemsControl的DataTemplate中的Canvas。有另一個畫布會混淆ZIndex的渲染。之後,我相信你可以將ZIndex綁定到實體的屬性(InGame集合中的項目) –
@ShawnKendrot沒有畫布的元素不呈現,所以這是不可能的? – JTIM
當然它會被渲染。 ItemsControl不需要Canvas在DataTemplate中 –