静态扩展在WinRT-XAML中工作

本文关键字:工作 WinRT-XAML 扩展 静态 | 更新日期: 2023-09-27 18:03:42

编辑:这是本主题的继续:为选定的Listview项2禁用蓝色边框

我想在Windows 8.1的应用程序中这样做:

<ListView x:Name="gui_listView" HorizontalAlignment="Left" 
      Height="610" Margin="48,54,0,0" VerticalAlignment="Top" 
      Width="256" SelectionChanged="gui_listView_SelectionChanged" 
      SelectionMode="Extended">
        <ListView.Resources>
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" 
             Color="Transparent"/>
        </ListView.Resources>
    </ListView>

但是微软可能停止了对静态扩展的支持。有人知道我现在该怎么做吗?这是我得到的误差图。http://imagizer.imageshack.us/a/img835/4764/jlcc9.jpg

感谢您的回复

静态扩展在WinRT-XAML中工作

事实是x:Static没有停止工作,它从来没有在Windows运行时工作过。所有的绑定都是针对Windows运行时中的实例对象。我意识到这绝对不同于WPF。但它就是这样,最简单的解决方法是在视图模型中包装静态引用。

public static class Information
{
    public static string Secret = "8675309";
}
public class MyViewModel 
{
    public string Secret { get { return Information.Secret; } }
}
祝你好运!

由于您的问题中提出了两个问题,所以我将提供两个答案。要删除鼠标悬停效果,需要重写主题值。在app.xaml.

<Application
    x:Class="App41.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App41">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.ThemeDictionaries>
                <ResourceDictionary x:Key="Default">
                    <SolidColorBrush x:Key="ListViewItemPointerOverBackgroundThemeBrush" Color="Transparent" />
                </ResourceDictionary>
            </ResourceDictionary.ThemeDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

这是嵌入在样式本身中的整个列表:

<ListViewItemPresenter 
    CheckHintBrush="{ThemeResource ListViewItemCheckHintThemeBrush}" 
    CheckBrush="{ThemeResource ListViewItemCheckThemeBrush}" 
    ContentMargin="4" 
    ContentTransitions="{TemplateBinding ContentTransitions}" 
    CheckSelectingBrush="{ThemeResource ListViewItemCheckSelectingThemeBrush}" 
    DragForeground="{ThemeResource ListViewItemDragForegroundThemeBrush}" 
    DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}" 
    DragBackground="{ThemeResource ListViewItemDragBackgroundThemeBrush}" 
    DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}" 
    FocusBorderBrush="{ThemeResource ListViewItemFocusBorderThemeBrush}" 
    HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" 
    Padding="{TemplateBinding Padding}" PointerOverBackgroundMargin="1" 
    PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" 
    PointerOverBackground="{ThemeResource ListViewItemPointerOverBackgroundThemeBrush}" 
    ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}" 
    SelectedPointerOverBorderBrush="{ThemeResource ListViewItemSelectedPointerOverBorderThemeBrush}" 
    SelectionCheckMarkVisualEnabled="True" 
    SelectedForeground="{ThemeResource ListViewItemSelectedForegroundThemeBrush}" 
    SelectedPointerOverBackground="{ThemeResource ListViewItemSelectedPointerOverBackgroundThemeBrush}" 
    SelectedBorderThickness="{ThemeResource ListViewItemCompactSelectedBorderThemeThickness}" 
    SelectedBackground="{ThemeResource ListViewItemSelectedBackgroundThemeBrush}" 
    VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
祝你好运!

试试这个:
MSDN ListView样式
把它放在你的WindowUC Resources标签。
现在找到VisualState,它负责突出显示,并更改为您喜欢的。
HTH
P.S.我没有发布现成的解决方案的原因是,你会从找出哪一部分负责高亮中受益更多,这将使开发更容易。