2010-12-13 51 views
1

我想让列表框中的悬停项目增加其字体大小,以便在用户浏览项目时获得某种“滚动效果”。我不知道如何去做这件事。我的列表框看起来像这样增加WPF列表框中的悬停元素的字体大小

<ListBox Name="ListBox" ItemsSource="{Binding MyList}" DisplayMemberPath="Property1"> 

感谢

回答

1

您应该能够使用触发器来做到这一点。像这样的东西

<ListBox Name="ListBox" ItemsSource="{Binding MyList}" DisplayMemberPath="Property1"> 
    <ListBox.ItemContainerStyle> 
     <Style TargetType="ListBoxItem"> 
      <Style.Triggers> 
       <Trigger Property="IsMouseOver" Value="True"> 
        <Setter Property="TextBlock.FontSize" Value="18"/> 
       </Trigger> 
      </Style.Triggers> 
     </Style> 
    </ListBox.ItemContainerStyle> 
</ListBox> 
+0

谢谢,很好! – Alex 2010-12-14 08:39:28

0

Meleak的答案是如何去做你所问的。但是当你这样做时,你会发现整个列表框是在你改变其中一个成员的字体大小的时候被布置的,这可能是不可取的。你可以尝试,而不是设置字体大小,将缩放变换:

<ListBox.ItemContainerStyle> 
    <Style TargetType="ListBoxItem"> 
     <Style.Triggers> 
      <Trigger Property="IsMouseOver" Value="True"> 
       <Setter Property="RenderTransform"> 
        <Setter.Value> 
        <ScaleTransform ScaleX="2" ScaleY="2"/> 
        </Setter.Value> 
       </Setter> 
      </Trigger> 
     </Style.Triggers> 
    </Style> 
</ListBox.ItemContainerStyle> 

由于这是一个RenderTransform(而不是LayoutTransform),它不会影响列表框的布局。还有其他问题(比如,你需要处理项目的背景,因为它们在重叠时会重叠),但是值得尝试。

+0

感谢您的建议!然而,我在使用这个时遇到了一些严重的重叠(像你提到的那样) – Alex 2010-12-14 08:41:32

+0

是的,你可能会发现为了使它工作得很好,你需要使模板中的顶层元素成为一个带有非透明'背景'。尽管有一个好处,那就是你也可以做一些事情,比如当鼠标悬停在项目上时,将BorderThickness设置为非零。如果你玩这个,你可以得到一些非常好的效果。 – 2010-12-14 19:25:50

+0

我一定会那样做的!再次感谢您的回答 – Alex 2010-12-14 20:59:13