1
有幾個答案,但沒有一個適用於UWP,只有WPF。我有一個自定義的ItemsControl,它根據孩子各自視圖模型中的屬性動態地將其子元素放置在一個不尋常的模式中。項目部分重疊,我需要確保所選項目不隱藏在任何其他項目下。但我無法弄清楚如何將一個值綁定到Grid的Z-index上。如何在帶有數據綁定的ItemsControl中設置Z-Index?
<ItemsControl Name="myItemsControl" ItemsSource="{x:Bind PageViewModel.myCollectionOfMyViewModel}" RenderTransformOrigin="0.5,0.5" >
<ItemsControl.RenderTransform>
<CompositeTransform x:Name="myTransform" />
</ItemsControl.RenderTransform>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="viewmodel:MyViewModel">
<Grid Name="ItemGrid" Canvas.ZIndex="{x:Bind SelectedItem, Mode=OneWay, Converter={StaticResource SelectedItemToZindexConverter}}" RenderTransformOrigin="0.5,0.5" >
<Grid.RenderTransform>
<CompositeTransform Rotation="{Binding ItemIdxNum, Mode=OneWay, Converter={StaticResource ItemIdxToRotationAngleConverter}}"
TranslateX="{Binding ItemIdxNum, Mode=OneWay, Converter={StaticResource ItemIdxToXPosConverter}}"
TranslateY="{Binding ItemIdxNum, Mode=OneWay, Converter={StaticResource ItemIdxToYPosConverter}}"
ScaleX="{x:Bind SelectedItem, Mode=OneWay, Converter={StaticResource SelectedItemBoolToScaleConverter}}"
ScaleY="{x:Bind SelectedItem, Mode=OneWay, Converter={StaticResource SelectedItemBoolToScaleConverter}}"
/>
</Grid.RenderTransform>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{x:Bind ItemName, Mode=OneWay}"/>
</StackPanel>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
那裏的Canvas.Zindex不會引發構建錯誤,但它不起作用。在這裏和其他地方搜索似乎我需要定位ItemsControl的ContentPresenter而不是子元素。但我不知道如何去做這件事。所有示例都是針對WPF的,並使用UWP中不提供的Style觸發器目標類型。
錯字是隻有在這裏利用這一點,我的錯誤,我編輯的職位與修正。正如我所說,它建立良好。事實上,如果我手動添加項目,它工作正常。但是與數據模板做一個ItemsSource綁定是行不通的。 –
這是一個有相同問題的人的例子。但正如我所提到的解決方案是爲WPF提供的,並不適用於UWP。 http://stackoverflow.com/questions/39637903/how-to-overlay-items-in-stackpanel-or-listview/39640662 –
{Windows.UI.Xaml.Markup.XamlParseException:與此錯誤代碼相關的文本不能被發現。 找不到與名稱/密鑰SelectedItemBoolToZindexConverter資源[線路:454職位:129] 在Windows.UI.Xaml.DataTemplate.LoadContent() 在Tilted.CustomControls.MyItemsControl.GetContainerForItemOverride()} –