2011-12-31 5 views
1

マウスが終わったときにリストアイテムの背景色を変更する必要があります。ここに私のコードです:ListBoxItemの背景色を変更しました。リストボックスアイテムの上にマウスがあるとき

<DataTemplate x:Key="ListBoxSubCategoryListTemplate" DataType="{x:Type ListBoxItem}"> 
     <StackPanel> 
      <Button x:Name="btnSubCategoryList" Template="{StaticResource subCategoryListItems}" 
        Content="{Binding Path=sub_category_name}" 
        Background="Transparent" 
        Height="25"/> 
     </StackPanel> 
    </DataTemplate> 

    <ControlTemplate x:Key="subCategoryListItems" TargetType="{x:Type Button}"> 
     <StackPanel FlowDirection="LeftToRight" Orientation="Horizontal" > 
      <TextBlock Width="150" 
         Height="{TemplateBinding Button.Height}" 
         x:Name="textBlockSubCategoryName" 
         Background="{TemplateBinding Button.Background}" 
         Text="{TemplateBinding Button.Content}" 
         FontWeight="Bold" /> 
      <Image x:Name="img" Width="15" Height="15" Source="/ExpressFurnitureSystem;component/Images/edit.png" ToolTip="Click to edit"></Image> 
     </StackPanel> 
    </ControlTemplate> 

どうすればいいですか?

答えて

3

どの程度Triggerなど:あなたの助け、デイブのため

<DataTemplate x:Key="ListBoxSubCategoryListTemplate" DataType="{x:Type ListBoxItem}"> 
    <StackPanel> 
     <Button x:Name="btnSubCategoryList" Template="{StaticResource subCategoryListItems}" 
       Content="{Binding Path=sub_category_name}" 
       Background="Transparent" 
       Height="25"/> 
    </StackPanel> 
    <DataTemplate.Triggers> 
     <Trigger Property="IsMouseOver" Value="True"> 
      <Setter TargetName="btnSubCategoryList" Property="Background" Value="Blue" /> 
     </Trigger> 
    </DataTemplate.Triggers> 
</DataTemplate> 
+0

感謝。 – usergaro

+0

大歓迎です! –

関連する問題