2008-12-23 115 views
0

我有一个ListPanel,它包含一个包含图像和标签的StackPanel。WPF ListBox DataTemplate和Image问题

<ListBox.ItemsPanel> 
    <ItemsPanelTemplate> 
     <VirtualizingStackPanel Orientation="Horizontal" IsItemsHost="True" /> 
    </ItemsPanelTemplate> 
</ListBox.ItemsPanel> 
<ListBox.ItemTemplate> 
    <DataTemplate> 
     <StackPanel Orientation="Vertical"> 
      <Image Source="{Binding Image}" Cursor="Hand" Tag="{Binding Link}" MouseLeftButtonDown="Image_MouseLeftButtonDown" ToolTip="Click to see this product on adidas.com" VerticalAlignment="Top" HorizontalAlignment="Left" /> 
      <Label Content="{Binding Name}" Cursor="Hand" Tag="{Binding Link}" MouseLeftButtonDown="Label_MouseLeftButtonDown" VerticalAlignment="Bottom" Foreground="White" Style="{StaticResource Gotham-Medium}" FontSize="8pt" HorizontalAlignment="Center" /> 
     </StackPanel> 
    </DataTemplate> 
</ListBox.ItemTemplate> 

我想在当前蒙上的图像后面显示第三个图像(glow.png)。我似乎无法添加第二个图像到堆叠面板,并将其设置为隐藏状态。我甚至还没有解决鼠标悬停的部分。

是否在堆叠面板中添加另一个图像,然后将其设置为可见性,以便在mouseenter上看到正确的方法,然后在mouseleave上交换回来?

谢谢。

回答

2

你当然可以有一个图像在另一个之后。而不是直接添加图片到你的StackPanel,添加一个网格,然后添加两个图像,像这样:

<StackPanel Orientation="Vertical"> 
    <Grid> 
     <Image Source="..." /> 
     <Image Source="{Binding Image}" ... /> 
    </Grid> 
    <Label Content="{Binding Name}" ... /> 
</StackPanel> 

你也可能想看看Bitmap Effects,使用它你可以引入到任何一个“发光”效果WPF元素。

编辑:实现你想要的效果的另一种方法(我相信)是在触发器中换出图像的Source属性。我不打算从内存中写入XAML,但是您可以捕获图像本身的IsMouseOver属性,并且当它切换为True时,可以将其Source设置为图像的“发光”版本。

+0

使用的位图的影响,谢谢,好主意。 – 2008-12-23 05:11:16

1

另一种可能性是边框添加到您的图片,设置为任何你想要的borderbrush的颜色和不透明度为0。您的MouseEnter事件处理程序设置不透明度为1