【问题标题】:How to Remove mouse hover effect in ListView Items Xamarin Forms UWP?如何在 ListView Items Xamarin Forms UWP 中删除鼠标悬停效果?
【发布时间】:2019-12-14 17:15:08
【问题描述】:

想要在 Xamarin 表单 UWP 中移除列表视图项上的鼠标悬停颜色

怎么做?

【问题讨论】:

    标签: xamarin.forms


    【解决方案1】:

    您可以在UWP项目App.xaml中修改listViewItem PointerOverBackground:Transparent

    <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;
                }
    
            }
        }
    }
    

    【讨论】:

    • 如何在 xamarin forms PCL 项目中应用这种风格?
    猜你喜欢
    • 2013-06-15
    • 2011-06-20
    • 2018-01-30
    • 2013-01-17
    • 2016-07-15
    • 1970-01-01
    • 2016-04-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多