0

我创建了以下名为“InertListView”的 wpf 控件,它是一个自定义 ListView:

<Plugins:InertListView    ItemsSource="{Binding Path=Data.InputPorts}"
                          Grid.Column="0" 
                          Background="Transparent"
                          BorderThickness="0"
                          BorderBrush="{x:Null}"
                          >
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition Width="Auto" />
                                        </Grid.ColumnDefinitions>
                                        <Path   Name="LeftPort" 
                                                Fill="{Binding Color}"   
                                                go:Node.PortId="{Binding Type}"
                                                Tag="Left"
                                                go:Node.LinkableFrom="False" 
                                                go:Node.LinkableTo="True"
                                                go:Node.ToSpot="MiddleLeft"
                                                go:Node.LinkableMaximum="1"
                                                Grid.Column="0"
                                                VerticalAlignment="Center"
                                                HorizontalAlignment="Left"
                                                Cursor="Hand"
                                                Width="10.968" 
                                                Height="14"
                                                Stretch="Fill" 
                                                StrokeThickness="2" 
                                                StrokeMiterLimit="2.75" 
                                                Stroke="#FF535755" 
                                                Data="F1 M 16.9835,22.9609C 16.7301,23.2861 16.1852,23.5528 15.7721,23.5528L 12.7187,23.553C 12.3071,23.553 11.9687,23.2161 11.9687,22.803L 11.9687,12.3032C 11.9687,11.8901 12.3071,11.5532 12.7187,11.5532L 15.7721,11.553C 16.1852,11.553 16.7301,11.8196 16.9835,12.1447L 20.7466,16.961C 21,17.2862 21,17.8195 20.7466,18.1447L 16.9835,22.9609 Z " 
                                                />
                                        <TextBlock x:Name="LabelPortLabel" 
                                                TextAlignment="Left" 
                                                FontFamily="/Connect IO;component/Fonts/#Segoe UI" 
                                                Grid.Column="1"
                                                VerticalAlignment="Center"
                                                FontSize="13" 
                                                Width="Auto" 
                                                Height="Auto" 
                                                Canvas.Top="0"
                                                Text="{Binding Label}"
                                                Margin="5 0 0 0"
                                                Cursor="Arrow"      
                                                />
                                    </Grid>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                        </Plugins:InertListView>

下面我展示了我如何定义“InertListView”:

public class InertListView : ListView
{
    protected override DependencyObject GetContainerForItemOverride()
    {
        return new InertListViewItem();
    }

}

public class InertListViewItem : ListViewItem
{
    protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
    {
        //base.OnMouseLeftButtonDown(e);
        //e.Handled = false;
    }
}

我的问题是,当我将鼠标移到其中一个 ListViewItems 上时,会出现一个突出显示的蓝色矩形。我怎样才能避免这种行为?

提前致谢!

里卡多

4

2 回答 2

0

您需要更改控件的模板。像这样的东西:

<Plugins:InertListView>
    ......
    ......
    <Plugins:InertListView.ItemContainerStyle>
        <Style TargetType="{x:Type ListViewItem}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListViewItem}">
                        <Border x:Name="Bd"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}">
                            <ContentPresenter Margin="{TemplateBinding Padding}"
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Plugins:InertListView.ItemContainerStyle>
</Plugins:InertListView>
于 2013-10-31T17:49:58.443 回答
0

覆盖 HighlightBrush,如下所示:

<Plugins:InertListView    ItemsSource="{Binding Path=Data.InputPorts}"
                          Grid.Column="0" 
                          Background="Transparent"
                          BorderThickness="0"
                          BorderBrush="{x:Null}"
                          >
<Plugins:InertListView.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
                             Color="Transparent"/>
</Plugins:InertListView.Resources>
于 2013-10-31T17:46:32.397 回答