Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/147.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 鼠标悬停在ListBoxItem上时更改ListBoxItem背景色_Wpf_Background_Datatemplate_Listboxitem - Fatal编程技术网

Wpf 鼠标悬停在ListBoxItem上时更改ListBoxItem背景色

Wpf 鼠标悬停在ListBoxItem上时更改ListBoxItem背景色,wpf,background,datatemplate,listboxitem,Wpf,Background,Datatemplate,Listboxitem,我需要设置更改列表项的背景色,当鼠标悬停时。这是我的密码: <DataTemplate x:Key="ListBoxSubCategoryListTemplate" DataType="{x:Type ListBoxItem}"> <StackPanel> <Button x:Name="btnSubCategoryList" Template="{StaticResource subCategoryListItems

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

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


请帮助…如何使用触发器,例如:

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