WPF-ListBox的N*N布局与鼠标进入ListBoxItem中显示按钮

来源:转载

N*N布局的ListBox,当鼠标进入列表区域的时候ListBoxItem项中的按钮会在底部渐显,离开后渐隐

最近肚子闹得厉害,也不多写了,就记一下刚实验的结果了。。

样式代码,主要是ListBoxItem的样式:

<Style TargetType="{x:Type ListBoxItem}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ListBoxItem}"> <Border x:Name="PART_Border" Margin="2" Width="200" Height="200" Background="Blue" BorderBrush="Black" BorderThickness="1"> <Grid> <WrapPanel x:Name="OpationPanel" Opacity="0" HorizontalAlignment="Right" VerticalAlignment="Bottom"> <Button Width="24" Height="24"/> <Button Width="24" Height="24"/> </WrapPanel> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="ListBoxItem.IsMouseOver" Value="True"> <Setter Property="Effect"> <Setter.Value> <DropShadowEffect BlurRadius="30" Color="Black" Direction="0" Opacity="0.6" RenderingBias="Performance" ShadowDepth="0" /> </Setter.Value> </Setter> <Trigger.EnterActions> <BeginStoryboard> <Storyboard> <DoubleAnimation BeginTime="0:0:0" Storyboard.TargetName="OpationPanel" Storyboard.TargetProperty="Opacity" Duration="0:0:0.4" From="0" To="1"/> </Storyboard> </BeginStoryboard> </Trigger.EnterActions> <Trigger.ExitActions> <BeginStoryboard> <Storyboard> <DoubleAnimation BeginTime="0:0:0" Storyboard.TargetName="OpationPanel" Storyboard.TargetProperty="Opacity" Duration="0:0:0.4" From="1" To="0"/> </Storyboard> </BeginStoryboard> </Trigger.ExitActions> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter></Style>

  调用代码,这里面包括了如何N*N布局ListBox:

<ListBox> <ListBox.ItemsPanel> <ItemsPanelTemplate> <!--使布局可以N*N排列--> <UniformGrid/> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBoxItem Content="ITEM" /> <ListBoxItem Content="ITEM" /> <ListBoxItem Content="ITEM" /> <ListBoxItem Content="ITEM" /> <ListBoxItem Content="ITEM" /> <ListBoxItem Content="ITEM" /> <ListBoxItem Content="ITEM" /> <ListBoxItem Content="ITEM" /> <ListBoxItem Content="ITEM" /></ListBox>

原文地址:http://www.luacloud.com/2011/06/27/wpf-listbox%e7%9a%84nn%e5%b8%83%e5%b1%80%e4%b8%8e%e9%bc%a0%e6%a0%87%e8%bf%9b%e5%85%a5listboxitem%e4%b8%ad%e6%98%be%e7%a4%ba%e6%8c%89%e9%92%ae/

分享给朋友:
您可能感兴趣的文章:
随机阅读: