修改ItemsControl中的项目的ZIndex [英] Modify ZIndex of an Items in an ItemsControl

查看:77
本文介绍了修改ItemsControl中的项目的ZIndex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的ItemsControl的代码,当鼠标悬停时,该代码会放大项目.
我没有设法增加当前缩放项目的ZIndex使其超过其他项目.

Here is the code of my ItemsControl that zooms on items when the mouse goes over.
I don't manage to increase the ZIndex of the current zoomed item to put it over the others.

<ItemsControl ItemsSource="{Binding Path=Value}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Path=Name}"
                       RenderTransformOrigin="0.5 0.5">
                <TextBlock.Style>
                    <Style TargetType="{x:Type TextBlock}">
                        <Style.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="RenderTransform">
                                    <Setter.Value>
                                        <ScaleTransform ScaleX="1.5"
                                                        ScaleY="1.5" />
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </TextBlock.Style>
            </TextBlock>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
    <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel Orientation="Horizontal" />
            </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>

我试图直接在触发器中更改ZIndex,但是它不起作用.
似乎我需要在ContentPresenter中更改ZIndex,该内容是VisualTree中TextBlock的父级,而不是直接在TextBlock中.

I tried to change directly the ZIndex in the trigger, but it doesn't work.
It seems that I need to change the ZIndex in the ContentPresenter that is the Parent of the TextBlock in the VisualTree and not directly in the TextBlock.

<Setter Property="Panel.ZIndex" Value="99" />

所以我试图在ContentPresenter中更改ZIndex,但是它仍然不起作用

So I tried to change the ZIndex in the ContentPresenter, but it still doesn't work

<ItemsControl.ItemContainerStyle>
    <Style TargetType="{x:Type ContentPresenter}">
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Panel.ZIndex" Value="99" />
            </Trigger>
        </Style.Triggers>
    </Style>
</ItemsControl.ItemContainerStyle>

有人知道它是如何工作的吗?

Does anyone know how it works ?

推荐答案

我完全尝试了WPF 4中的建议,效果很好.

I just tried exactly what you suggested in WPF 4 and it worked fine.

MainWindow.xaml :

<Window x:Class="SO9687674.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <ItemsControl ItemsSource="{Binding}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding}">
                <TextBlock.Style>
                    <Style TargetType="{x:Type TextBlock}">
                        <Style.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="RenderTransform">
                                    <Setter.Value>
                                        <ScaleTransform ScaleX="2.5"
                                                        ScaleY="2.5" />
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </TextBlock.Style>
                </TextBlock>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
        <ItemsControl.ItemContainerStyle>
            <Style TargetType="{x:Type ContentPresenter}">
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Panel.ZIndex" Value="99" />
                    </Trigger>
                </Style.Triggers>
            </Style>
        </ItemsControl.ItemContainerStyle>
    </ItemsControl>
</Window>

MainWindow.xaml.cs :

using System.Collections.Generic;
using System.Windows;

namespace SO9687674
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            this.DataContext = new List<string>
            {
                "One",
                "two",
                "three"
            };
        }
    }
}

是什么让您认为它不起作用?您是否已使用Snoop进行验证?

What makes you think it's not working? Have you used Snoop to verify?

这篇关于修改ItemsControl中的项目的ZIndex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆