将样式键设置为静态ResourceKey会锁定智能感知自动完成,只要它包含在自动列出的成员中

时间:2016-05-12 21:52:19

标签: c# visual-studio xaml visual-studio-2013 visual-studio-2015

摘要

将样式的x:Key分配给静态ResourceKey时,如果包含该项,XAML智能感知会锁定自动填充字段。该项目显示为空白(无名称)项目,并导致在除Arrow KeysDelete之外的自动完成框内按任何键盘按键锁定。无法按Enter,无法继续键入资源名称,只需将其从其他位置粘贴或在列表中双击即可。这显然非常烦人。

我在2台计算机上试过这个(1个没有安装任何扩展程序),并且在Visual Studio 2015和2013中使用各种Text Editor设置进​​行了修改,但没有好处。我从头开始重新创建项目,看看它是否只是错误的缓存数据或其他东西,但仍然没有好处。在使用Resharper时,人们似乎遇到了类似的问题,但禁用它并清除安装了Resharper的计算机上的缓存也没有解决问题。

因为我知道这是如何将ResourceKey分配给模板/样式的常用方法,而我找不到任何关于我特定问题的内容,我想我必须在这里做错事。但无论我制作这个项目多么简单,或者我对它做了多少小改动,问题仍然存在。

enter image description here

代码

MainWindow.xaml

<Window x:Class="WpfTestApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:theme="clr-namespace:WpfTestApp.Theme"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <Style x:Key="{x:Static theme:SharedStyleKeys.ButtonBaseStyleKey}" TargetType="{x:Type ButtonBase}">
            <Setter Property="Background" Value="Black" />
            <Setter Property="Foreground" Value="White" />
            <Setter Property="Height" Value="24" />
        </Style>

        <Style x:Key="ButtonBaseStyleKeyThatWorks" TargetType="{x:Type ButtonBase}">
            <Setter Property="Background" Value="White" />
            <Setter Property="Foreground" Value="Black" />
            <Setter Property="Height" Value="24" />
        </Style>
    </Window.Resources>
    <StackPanel>
        <Button Style="{StaticResource ButtonBaseStyleKeyThatWorks}" />
        <Button Style="{StaticResource {x:Static theme:SharedStyleKeys.ButtonBaseStyleKey}}" />
        <Button Style="{StaticResource <!--Type here-->}" />
    </StackPanel>
</Window>

主题/ SharedStyleKeys.cs

using System.Windows;

namespace WpfTestApp.Theme
{
    public static class SharedStyleKeys
    {
        private static ComponentResourceKey buttonBaseStyleKey = new ComponentResourceKey(typeof(SharedStyleKeys), (object)"ButtonBaseStyleKey");
        public static ResourceKey ButtonBaseStyleKey
        {
            get { return buttonBaseStyleKey; }
        }
    }
}

0 个答案:

没有答案