[code=XAML]
<Style x:Key="styleListBoxChannel1" TargetType="{x:Type ListBox}">
<Setter Property="BorderBrush" Value="{x:Null}"></Setter>
<Setter Property="Background" Value="{x:Null}"></Setter>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled"></Setter>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"></Setter>
<Setter Property="ItemContainerStyle" Value="{DynamicResource styleListBoxItemChannel1}"></Setter>
<Setter Property="FocusVisualStyle">
<Setter.Value>
<Style></Style>
</Setter.Value>
</Setter>
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel>
<Image x:Name="image" Width="32" Height="32" Source="{Binding Mode=OneWay, XPath=@ImageName, Converter={StaticResource imagePathConversion}}">
<Image.ToolTip>
<ToolTip Style="{DynamicResource CustomerToopTip}" BorderThickness="0">
<TextBlock Text="{Binding Mode=OneWay, XPath=@Name}" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Stretch" FontFamily="Segoe" Foreground="White"/>
</ToolTip>
</Image.ToolTip>
</Image></StackPanel>
</DataTemplate>
</Setter.Value>
</Setter> <Style x:Key="styleListBoxItemChannel1" TargetType="{x:Type ListBoxItem}">
<Setter Property="Cursor" Value="Hand"></Setter>
<Setter Property="Margin" Value="7,0,8,0"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Opacity" Value="1"/>
<Setter Property="Foreground" Value="#FFFFFF"/>
<Setter Property="RenderTransformOrigin" Value="0.5 1"/>
<Setter Property="FocusVisualStyle">
<Setter.Value>
<Style></Style>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<ContentPresenter x:Name="contentPresenter" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<!--<Setter Property="FocusVisualStyle" TargetName="contentPresenter">
<Setter.Value>
<Style></Style>
</Setter.Value>
</Setter>-->
<Setter Property="Foreground" Value="red"></Setter>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<!--<Setter Property="Foreground" Value="red"></Setter>-->
<Setter Property="Content">
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
[/code]上面是一个Listbox的自定义样式 每个ListBoxItem都绑定一个图片,现在我想实现的功能是 鼠标移动到每个ListBoxItem的图片上时 该图片替换成效果图片 我想用IsMouseOver属性可是不知道怎么实现 或者有什么其他方法 谢谢
<Style x:Key="styleListBoxChannel1" TargetType="{x:Type ListBox}">
<Setter Property="BorderBrush" Value="{x:Null}"></Setter>
<Setter Property="Background" Value="{x:Null}"></Setter>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled"></Setter>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"></Setter>
<Setter Property="ItemContainerStyle" Value="{DynamicResource styleListBoxItemChannel1}"></Setter>
<Setter Property="FocusVisualStyle">
<Setter.Value>
<Style></Style>
</Setter.Value>
</Setter>
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel>
<Image x:Name="image" Width="32" Height="32" Source="{Binding Mode=OneWay, XPath=@ImageName, Converter={StaticResource imagePathConversion}}">
<Image.ToolTip>
<ToolTip Style="{DynamicResource CustomerToopTip}" BorderThickness="0">
<TextBlock Text="{Binding Mode=OneWay, XPath=@Name}" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Stretch" FontFamily="Segoe" Foreground="White"/>
</ToolTip>
</Image.ToolTip>
</Image></StackPanel>
</DataTemplate>
</Setter.Value>
</Setter> <Style x:Key="styleListBoxItemChannel1" TargetType="{x:Type ListBoxItem}">
<Setter Property="Cursor" Value="Hand"></Setter>
<Setter Property="Margin" Value="7,0,8,0"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Opacity" Value="1"/>
<Setter Property="Foreground" Value="#FFFFFF"/>
<Setter Property="RenderTransformOrigin" Value="0.5 1"/>
<Setter Property="FocusVisualStyle">
<Setter.Value>
<Style></Style>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<ContentPresenter x:Name="contentPresenter" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<!--<Setter Property="FocusVisualStyle" TargetName="contentPresenter">
<Setter.Value>
<Style></Style>
</Setter.Value>
</Setter>-->
<Setter Property="Foreground" Value="red"></Setter>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<!--<Setter Property="Foreground" Value="red"></Setter>-->
<Setter Property="Content">
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
[/code]上面是一个Listbox的自定义样式 每个ListBoxItem都绑定一个图片,现在我想实现的功能是 鼠标移动到每个ListBoxItem的图片上时 该图片替换成效果图片 我想用IsMouseOver属性可是不知道怎么实现 或者有什么其他方法 谢谢
[code=XAML]
<Style x:Key="styleListBoxChannel1" TargetType="{x:Type ListBox}">
.....
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
</T
</Style.Triggers>
</Style>
[/code]
<Style x:Key="styleListBoxChannel1" TargetType="{x:Type ListBox}">
<Setter Property="BorderBrush" Value="{x:Null}"></Setter>
<Setter Property="Background" Value="{x:Null}"></Setter>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled"></Setter>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"></Setter>
<Setter Property="ItemContainerStyle" Value="{DynamicResource styleListBoxItemChannel1}"></Setter>
<Setter Property="FocusVisualStyle">
<Setter.Value>
<Style></Style>
</Setter.Value>
</Setter>
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel>
<Image x:Name="image" Width="50" Height="49" Source="{Binding Mode=OneWay, XPath=@ImageName, Converter={StaticResource imagePathConversion}}">
<Image.ToolTip>
<ToolTip Style="{StaticResource styleToopTipChannel}">
<TextBlock Text="{Binding Mode=OneWay, XPath=@Name}" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Stretch" FontFamily="宋体" Foreground="White"/>
</ToolTip>
</Image.ToolTip>
</Image> <!--<TextBlock Name="tBlock" Text="{Binding Mode=OneWay, XPath=@Name}" HorizontalAlignment="Center" FontFamily="黑体" Visibility="Hidden" >-->
<!--</TextBlock>-->
</StackPanel>
<DataTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Source" TargetName="image" Value="{Binding Mode=OneWay, XPath=@ImageNameOver, Converter={StaticResource imagePathConversion}}"></Setter>
</Trigger>
</DataTemplate.Triggers>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center"></VirtualizingStackPanel>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
[/code]
ok 解决了 希望对新学者有所帮助