【问题标题】:Change ListBoxItem Background Color when mouse is over on the listBoxItem当鼠标悬停在 listBoxItem 上时更改 ListBoxItem 背景颜色
【发布时间】:2011-12-31 18:04:45
【问题描述】:

当鼠标悬停时,我需要为列表项设置更改背景颜色。这是我的代码:

    <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>

请帮忙...如何??

【问题讨论】:

    标签: wpf background datatemplate listboxitem


    【解决方案1】:

    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> 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-17
      • 2010-12-25
      相关资源
      最近更新 更多