Wpf 修改ItemsControl中项目的ZIndex

Wpf 修改ItemsControl中项目的ZIndex,wpf,z-index,itemscontrol,rendertransform,Wpf,Z Index,Itemscontrol,Rendertransform,这是“我的项目”控件的代码,当鼠标滑过该控件时,该控件将对项目进行缩放。 我无法通过增加当前缩放项目的ZIndex来将其置于其他项目之上 <ItemsControl ItemsSource="{Binding Path=Value}"> <ItemsControl.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Path=Name}"

这是“我的项目”控件的代码,当鼠标滑过该控件时,该控件将对项目进行缩放。
我无法通过增加当前缩放项目的ZIndex来将其置于其他项目之上

<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中

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

因此,我尝试更改ContentPresenter中的ZIndex,但仍然不起作用

<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>


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

我刚刚完全按照您在WPF 4中的建议进行了尝试,效果很好

主窗口.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>
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"
            };
        }
    }
}

main window.xaml.cs

<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>
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"
            };
        }
    }
}
使用System.Collections.Generic;
使用System.Windows;
名称空间SO9687674
{
公共部分类主窗口:窗口
{
公共主窗口()
{
初始化组件();
this.DataContext=新列表
{
“一个”,
“两个”,
“三个”
};
}
}
}

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

使用画布对我来说很好。所以你可能还有另一个问题。你用什么样的面板?我用包装纸。哪个解决方案对你有效?我认为它不起作用,因为我看到它不起作用:)我窥探它,当我的鼠标继续运行时,ZIndex不会改变。我将在一个新的项目中尝试您的示例。@Nicolas:冒着光顾的风险,您正在窥探容器,而不是
TextBlock
本身,对吗?@Nicolas唯一可能不起作用的方法是,如果您有其他东西编写Zindex属性。检查,如果某个具有较高优先级的对象正在写入zindex,则触发器值将被“忽略”,不会被真正忽略,但只要具有较高优先级的对象写入该值,则不会使用该值。@Kent:谢谢您的示例,我成功地使其工作。你让我重回正轨。我查找了这个问题,发现我有一个ItemsControl的连接,我把itemscontainerstyle放错了:(谢谢你的帮助。