在Telerik RadListView中为UWP删除项目选择上的defalt背景
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Telerik RadListView中为UWP删除项目选择上的defalt背景相关的知识,希望对你有一定的参考价值。
我在我的UWP应用程序中使用Telerik RadListView控件。我想删除RadlistView提供的默认选择背景,它在image here中以绿色显示
Telerik for UWP现在是开源的。你可以从GitHub看到它的所有代码:https://github.com/telerik/UI-For-UWP
对于您的问题,如果您在visual studio中调试项目并检查其可视化树,您会看到它实际上是一个名为“CheckBox”的Grid控件。
因此,我们需要做的是找到RadListViewItem的样式,并在选中时更改'CheckBackground [Path]'填充颜色。
然后,RadListViewItem的样式也可以在github:https://github.com/telerik/UI-For-UWP/blob/master/Controls/DataControls/DataControls.UWP/Themes/Generic.xaml#L705上找到
您可以复制它并将其应用于您自己的项目。为了满足您的要求,您只需要更改此样式中的“已选择”视觉状态。
我做了一个代码示例供您参考:
xmlns:telerikDataControls="using:Telerik.UI.Xaml.Controls.Data"
xmlns:listView="using:Telerik.UI.Xaml.Controls.Data.ListView"
<Grid>
<Grid.Resources>
<SolidColorBrush x:Key="TelerikSecondaryForegroundBrush" Color="#99FFFFFF" />
<SolidColorBrush x:Key="TelerikSelectedBrush" Color="#FF006AC1" />
<SolidColorBrush x:Key="TelerikHighlightBrush" Color="#FF006AC1" />
<Style TargetType="listView:RadListViewItem">
<Setter Property="TabNavigation" Value="Local" />
<Setter Property="UseSystemFocusVisuals" Value="True" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="4" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="FontSize" Value="20" />
<Setter Property="Padding" Value="5" />
<Setter Property="MinHeight" Value="55" />
<Setter Property="MinWidth" Value="55" />
<Setter Property="Margin" Value="5" />
<Setter Property="Canvas.ZIndex" Value="10" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="listView:RadListViewItem">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="grid" Storyboard.TargetProperty="Opacity">
<DiscreteObjectKeyFrame KeyTime="0" Value="{Binding DisabledStateOpacity, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="SelectedState">
<VisualState x:Name="Selected">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckBox" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="border" Storyboard.TargetProperty="BorderBrush">
<DiscreteObjectKeyFrame KeyTime="0" Value="Transparent" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Unselected">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckBox" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="border" Storyboard.TargetProperty="BorderBrush">
<DiscreteObjectKeyFrame KeyTime="0" Value="{Binding BorderBrush, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="ReorderState">
<VisualState x:Name="ReorderEnabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_ReorderHandle" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="ReorderDisabled" />
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid x:Name="grid" Background="{TemplateBinding Background}" Margin="{TemplateBinding Margin}">
<ContentControl x:Name="PART_Content" FontSize="{TemplateBinding FontSize}" Foreground="{TemplateBinding Foreground}" Margin="{TemplateBinding Padding}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalAlignment}"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"
IsTabStop="False" />
<Border x:Name="border"
IsHitTestVisible="False"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
以上是关于在Telerik RadListView中为UWP删除项目选择上的defalt背景的主要内容,如果未能解决你的问题,请参考以下文章
在 Telerik 的 RadListView 中预先选择复选框
Telerik UI Nativescript - RadListView 涟漪效应
RadListView Telerik UI“无法读取未定义的属性‘setLayoutParams’”
Xamarin Telerik RadListview 在 iOS 中不绑定