2012-03-13 4 views
6

다음은 마우스가 넘어갈 때 항목을 확대하는 ItemsControl의 코드입니다.
현재 확대/축소 된 항목의 ZIndex를 증가시켜 다른 항목 위에 올릴 수 없습니다.ItemsControl에서 항목의 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를 직접 변경하려고 시도했지만 작동하지 않습니다.
TextBlock의 TextTlock에있는 TextBlock의 부모 인 ContentPresenter에서 ZIndex를 변경해야하는 것으로 보입니다.

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

그래서 나는 ContentPresenter에의 Z- 색인을 변경했지만, 여전히 그것이 어떻게 작동하는지 아는 사람 있나요

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

를 작동하지 않는 이유는 무엇입니까?

+0

나를 위해 잘 작동, 캔버스를 사용합니다. 그래서 당신은 propably 다른 문제가 있습니다. 어떤 종류의 패널을 사용합니까? – dowhilefor

+0

WrapPanel을 사용합니다. 어떤 솔루션이 효과가 있습니까? – Nicolas

답변

10

방금 ​​WPF 4에서 제안한 것과 똑같은 방식으로 시도했지만 제대로 작동했습니다.

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" 
      }; 
     } 
    } 
} 

당신은 어떻게 생각 하죠? 확인하기 위해 스눕을 사용 했습니까?

+0

나는 그것을 보지 않기 때문에 나는 작동하지 않는다고 생각한다. 나는 그것을 스눕 (snoop)하고 ZIndex는 내 마우스가 계속 움직일 때 바뀌지 않는다. 신선한 프로젝트에서 당신의 예를 시험해 보겠습니다. – Nicolas

+0

@Nicolas : 가볍게 쓰는 위험에 처해 있는데, 당신은'TextBlock' 그 자체가 아닌 * 컨테이너 *를 기웃 거리고 있습니다, 맞습니까? –

+0

@ Nicolas는 Zindex 속성을 작성하는 다른 방법이있는 경우에만 작동하지 않을 수있는 유일한 방법입니다. [우선 순위 값] (http://msdn.microsoft.com/en-us/library/ms743230.aspx#listing)을 확인하십시오. 우선 순위가 높은 항목이 zindex를 쓰고 있으면 트리거 값은 "무시됩니다"가 아니라 정말로 무시되지만 더 높은 우선 순위가 값을 쓰는 한 사용되지 않습니다. – dowhilefor

관련 문제