Xamarin.forms 如何删除ListView项目中的鼠标悬停效果Xamarin表单UWP?

Xamarin.forms 如何删除ListView项目中的鼠标悬停效果Xamarin表单UWP?,xamarin.forms,Xamarin.forms,要删除Xamarin表单UWP中listview项上的鼠标悬停颜色吗 如何做到这一点?您可以在UWP project App.xaml中将listViewItemPointerOverBackground:修改为透明的 <Application x:Class="xxx.UWP.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.co

要删除Xamarin表单UWP中listview项上的鼠标悬停颜色吗


如何做到这一点?

您可以在UWP project App.xaml中将listViewItemPointerOverBackground:修改为透明的

<Application
x:Class="xxx.UWP.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:xxx.UWP"
RequestedTheme="Light">

<Application.Resources>
    <ResourceDictionary>

        <Style x:Key="ItemStyle" TargetType="ListViewItem">

            <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />

            <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />

            <Setter Property="Background" Value="Transparent" />

            <Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}" />

            <Setter Property="TabNavigation" Value="Local" />

            <Setter Property="IsHoldingEnabled" Value="True" />

            <Setter Property="Padding" Value="0" />

            <Setter Property="HorizontalContentAlignment" Value="Stretch" />

            <Setter Property="VerticalContentAlignment" Value="Center" />

            <Setter Property="MinWidth" Value="{ThemeResource ListViewItemMinWidth}" />

            <Setter Property="MinHeight" Value="0" />

            <Setter Property="Template">

                <Setter.Value>

                    <ControlTemplate TargetType="ListViewItem">

                        <ListViewItemPresenter
                            HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                            CheckBoxBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
                            CheckBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
                            CheckMode="Inline"
                            ContentMargin="{TemplateBinding Padding}"
                            ContentTransitions="{TemplateBinding ContentTransitions}"
                            DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}"
                            DragBackground="{ThemeResource ListViewItemDragBackgroundThemeBrush}"
                            DragForeground="{ThemeResource ListViewItemDragForegroundThemeBrush}"
                            DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}"
                            FocusBorderBrush="{ThemeResource SystemControlForegroundAltHighBrush}"
                            FocusSecondaryBorderBrush="{ThemeResource SystemControlForegroundBaseHighBrush}"
                            PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}"
                            PointerOverBackground="Transparent"
                            PointerOverForeground="{ThemeResource SystemControlHighlightAltBaseHighBrush}"
                            PressedBackground="{ThemeResource SystemControlHighlightListMediumBrush}"
                            ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}"
                            SelectedBackground="{ThemeResource SystemControlHighlightListAccentLowBrush}"
                            SelectedForeground="{ThemeResource SystemControlHighlightAltBaseHighBrush}"
                            SelectedPointerOverBackground="{ThemeResource SystemControlHighlightListAccentMediumBrush}"
                            SelectedPressedBackground="{ThemeResource SystemControlHighlightListAccentHighBrush}"
                            SelectionCheckMarkVisualEnabled="True" />

                    </ControlTemplate>

                </Setter.Value>

            </Setter>

        </Style>

    </ResourceDictionary>

</Application.Resources>

并将其应用于CustomRenderer

[assembly: ExportRenderer(typeof(Xamarin.Forms.ListView), typeof(CustomListViewRenderer))]
namespace xxx.UWP
{
    public class CustomListViewRenderer : ListViewRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                List.ItemContainerStyle = App.Current.Resources["ItemStyle"] as Windows.UI.Xaml.Style;
            }

        }
    }
}
[程序集:ExportRenderer(typeof(Xamarin.Forms.ListView)、typeof(CustomListViewRenderer))]
名称空间xxx.UWP
{
公共类CustomListViewRenderer:ListViewRenderer
{
受保护的覆盖无效OnElementChanged(ElementChangedEventArgs e)
{
基础。一个要素发生变化(e);
if(控件!=null)
{
List.ItemContainerStyle=App.Current.Resources[“ItemStyle”]作为Windows.UI.Xaml.Style;
}
}
}
}

如何在xamarin forms PCL项目中应用此样式?