Wpf C#中ListBox ItemTemplate中的鼠标悬停和背景颜色

问题描述

您好,我发现自己遇到了问题。我的任务是当我将鼠标悬停在任何 ListBox 值上时,行和线条颜色将发生变化。请注意使用 Border 的线条。我在互联网上找到了一些解决方案,但这与我的代码或逻辑不符。这是我的代码

 <ListBox
        x:Name="listBox1"
        Grid.Row="5"
        Height="360"
        Margin="6"
        SelectionMode="Single" >
         <ListBox.ItemContainerStyle>
            <Style targettype="ListBoxItem">
                <Style.Triggers>
                    <Trigger Property="IsMouSEOver" Value="True">

                        <Setter Property="Background" Value="Yellow"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </ListBox.ItemContainerStyle>
        <ListBox.ItemTemplate x:Uid="lititem"  >
            <DataTemplate >
                <Border BorderThickness="0,1" BorderBrush="Black" >
                    <Grid Margin="1">
                        <Grid.ColumnDeFinitions>
                            <ColumnDeFinition Width="*"/>
                            <ColumnDeFinition Width="auto" />
                            <ColumnDeFinition Width="auto" />
                        </Grid.ColumnDeFinitions>
                        <!--<Border BorderThickness="1" Grid.Column="0"
                        BorderBrush="Black">-->
                        <!--<TextBlock Grid.Column="0"  Margin="10,2,10,2"  Text="{Binding Path=傷病名}" />-->
                        <!--</Border>-->

                        <!--<Border BorderThickness="1" Grid.Column="1" BorderBrush="Black">-->
                        <Button
                        Grid.Column="1"
                        Margin="5,5,10"
                        Padding="5"
                        Background="#FF54CD54"
                        Command="{Binding ElementName=me,Path=Command確定}"
                        CommandParameter="{Binding}"
                        Foreground="White"
                        IsEnabled="{Binding Path=確定IsEnableFlag}">
                            <Run FontWeight="Bold">
                                確定病名
                            </Run>
                        </Button>
                        <Button
                        Grid.Column="2"
                        Margin="5,10"
                        Padding="5"
                        Background="#FFFF5656"
                        Command="{Binding ElementName=me,Path=Command疑い}"
                        CommandParameter="{Binding}"
                        Foreground="White"
                        IsEnabled="{Binding Path=疑いIsEnableFlag}">
                            <Run FontWeight="Bold">
                                疑い病名
                            </Run>
                        </Button>
                    </Grid>

                </Border>
            </DataTemplate>


        </ListBox.ItemTemplate>
  </ListBox>

如您所见,我在触发器属性 IsMouSEOver 上使用了悬停并将背景颜色更改为黄色,但它不起作用它正在更改为不同的颜色。并且通过使用 它也打破了我的网格列设计意味着网格列样式没有按预期工作。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)