【问题标题】:Do x:Static extensions work in WinRT-XAML?x:Static 扩展在 WinRT-XAML 中有效吗?
【发布时间】:2014-07-03 16:21:30
【问题描述】:

编辑:这是本主题的继续:Disable blue border for selected Listview item 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

感谢您的回复。

【问题讨论】:

  • 您是否将名称、对齐方式和尺寸分配给Resources 部分?
  • 我不知道你的意思..?你能说得更具体点吗?
  • 你真的设置x:NameHorizontalAlignmentHeight 等对ListView.ResourcesListView 吗?您粘贴的内容无法编译,而不是因为您提到的错误
  • 这是本主题的继续:stackoverflow.com/questions/23673464/…
  • 对不起,我粘贴了错误的代码,现在应该更好了。

标签: c# wpf windows winrt-xaml windows-8.1


【解决方案1】:

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

public static class Information
{
    public static string Secret = "8675309";
}

public class MyViewModel 
{
    public string Secret { get { return Information.Secret; } }
}

祝你好运!

【讨论】:

    【解决方案2】:

    由于您在问题中提出了两个问题,我将提供两个答案。要移除鼠标悬停效果,您需要覆盖主题值。您在 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}"/>
    

    祝你好运!

    【讨论】:

    • 非常感谢,但我还有一个奇怪的边框,鼠标悬停时可见,看图片。 i.imgur.com/dk0DYJr.jpg你不知道我怎样才能删除他吗?这是最后一个边界(或任何它),我需要删除什么......我希望如此。
    • 不是鼠标悬停的阴影,是选中的边框。我很惊讶它在鼠标悬停时未选中时可见。你确定你没有在某处覆盖另一种风格吗?
    【解决方案3】:

    试试这个:
    MSDN ListView styles
    把它放在你的 WindowUC Resources 标签中。
    现在找到负责突出显示的VisualState,并将其更改为您喜欢的。
    HTH
    附言我之所以没有发布现成的解决方案,是因为你会从找出负责突出显示的部分中受益更多,这将使开发更容易。

    【讨论】:

    • 我还是不知道。当你试图让我学会自给自足时,我很感激,但我真的是新手。你能否请我更详细地描述一下我该怎么做?根据我自己的经验,我知道,从代码中我会学到更多。不好,如果您复制一些代码并且您不知道哪个部分在做什么。如果您以这种方式描述我,我将如何逐步做到这一点,也许您会向我解释一些事情,我将不胜感激。 :))
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-11
    • 1970-01-01
    • 2011-01-08
    • 1970-01-01
    • 2021-12-01
    • 1970-01-01
    相关资源
    最近更新 更多