0

我有一个问题,我的列表视图中取消选择的项目在我取消选择后不显示“IsMouseOver”的颜色,除非我选择其他内容然后选择它。在我的 ItemContainerStyle 中,我将焦点/非焦点的默认颜色设置为透明,因为我想定义自己的值。谁能看看这个并告诉我为什么“IsMouseOver”对取消选择的项目不起作用?

xml:

<ListView Name="lstPhoneCarrier" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="408" Height="145" 
  ItemsSource="{Binding ShowAllCarrierInfo, Mode=TwoWay}" 
  ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Visible" 
  SelectionMode="Single">

<ListView.ItemContainerStyle>
    <Style TargetType="{x:Type ListViewItem}">
        <Style.Resources>
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
            <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
        </Style.Resources>
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background" Value="Yellow" />
            </Trigger>
        </Style.Triggers>
    </Style>
</ListView.ItemContainerStyle>

<ListView.ItemTemplate>
    <DataTemplate>
        <Label x:Name="lblCarrier" HorizontalAlignment="Left">
            <Label.Content>
                <StackPanel Orientation="Horizontal">
                    <TextBlock>
                        <TextBlock.Text>
                            <MultiBinding StringFormat="{}{0}-{1}">
                                <Binding Path="Name" />
                                <Binding Path="Description" />
                             </MultiBinding>
                        </TextBlock.Text>
                    </TextBlock>
                </StackPanel>
            </Label.Content>
        </Label>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding Path=CarrierSelected}" Value="True" >
                <Setter TargetName="lblCarrier" Property="Background" Value="Pink" />
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>
</ListView.ItemTemplate>

4

1 回答 1

0

您已经覆盖了高亮画笔,以便用户看不到选择,但内部selection仍在工作,captures the mouse因此MouseOver events not getting raised for that item.

您需要设置FocusablefalselistBoxItem以便鼠标不会被捕获ItemContainerStyle-

<ListView.ItemContainerStyle>
    <Style TargetType="{x:Type ListViewItem}">
         <Setter Property="Focusable" Value="False"/> // <---- HERE
        <Style.Resources>
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" 
                             Color="Transparent" />
            <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}"
                             Color="Transparent" />
        </Style.Resources>
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background" Value="Yellow" />
            </Trigger>
        </Style.Triggers>
    </Style>
</ListView.ItemContainerStyle>
于 2013-03-27T14:37:24.793 回答