我正在使用带有WPF的列表视图,我想删除Mouse Over上的突出显示颜色,我正在实现此代码。
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Transparent" />
</Trigger>
虽然它正在删除高亮颜色但不完全删除,但列表视图项目顶部有一个小灰色矩形框,如何完全删除此突出显示?
以下是附上的图片。
答案 0 :(得分:4)
Altamash,据我所知,白线的原因是因为wpf正在使用包含该配色方案的默认Windows Aero主题。为了修改它,您可以为ListViewItem编写自己的控件
<强>之前强>
<强>后强>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Style.Resources>
<SolidColorBrush x:Key="ListItemHoverFill" Color="LightBlue"/>
</Style.Resources>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListViewItem}">
<Border CornerRadius="0" SnapsToDevicePixels="True"
BorderThickness="0,-1,0,1"
BorderBrush="#dcdbd5"
Background="{TemplateBinding Background}">
<Border Name="InnerBorder" CornerRadius="0" BorderThickness="0">
<Grid>
<Rectangle Name="UpperHighlight" Visibility="Collapsed" Fill="Transparent" />
<GridViewRowPresenter Grid.RowSpan="0"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Grid>
</Border>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{StaticResource ListItemHoverFill}" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter TargetName="UpperHighlight" Property="Visibility" Value="Visible" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListView.ItemContainerStyle>
希望这会有所帮助;)
答案 1 :(得分:0)
可能为项目容器设置样式
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="Control.Focusable" Value="False"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{x:Null}" />
<Setter Property="BorderBrush" Value="{x:Null}" />
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
或者您可以使用多重触发
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="false"/>
<Condition Property="IsMouseOver" Value="true"/>
</MultiTrigger.Conditions>
答案 2 :(得分:0)
我的解决方案是设置经典主题:
public static void SetTheme(string themeName, string themeColor)
{
const BindingFlags staticNonPublic = BindingFlags.Static | BindingFlags.NonPublic;
var presentationFrameworkAsm = Assembly.GetAssembly(typeof(Window));
var themeWrapper = presentationFrameworkAsm.GetType("MS.Win32.UxThemeWrapper");
var isActiveField = themeWrapper.GetField("_isActive", staticNonPublic);
var themeColorField = themeWrapper.GetField("_themeColor", staticNonPublic);
var themeNameField = themeWrapper.GetField("_themeName", staticNonPublic);
// Set this to true so WPF doesn't default to classic.
isActiveField.SetValue(null, true);
themeColorField.SetValue(null, themeColor);
themeNameField.SetValue(null, themeName);
}
static App()
{
try
{
SetTheme("Classic", "NormalColor");
来源: http://northhorizon.net/2010/how-to-actually-change-the-system-theme-in-wpf/