[英]MouseOver And BackGround Color In ListBox ItemTemplate in Wpf C#
您好,我发现自己遇到了问题。 我的任务是当我将鼠标悬停在任何 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,0,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,10,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,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 上使用了悬停并将背景颜色更改为黄色,但它不起作用它正在更改为不同的颜色。 而且通过使用 <ListBox.ItemContainerStyle> 它也打破了我的网格列设计意味着网格列样式没有按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.