none
Setting style key to static ResourceKey locks up intellisense autocomplete whenever it included in the auto listed members

    Question

  • Summary

    When assigning a style's x:Key to a static ResourceKey, the XAML intellisense locks up the autocomplete field if the item is included. The item appears as a blank (no name) item and causes a lock-up of pressing any keyboard keys while within the autocomplete box besides Arrow Keys and Delete. Can't press Enter, can't continue typing the name of the resource, just have to paste it in from somewhere else or double-click it in the list. This is obviously very annoying.

    I've tried this on 2 computers (1 without any extensions installed) and in Visual Studio 2015 and 2013 and tinkered with various Text Editor settings, but no good. I recreated the project from scratch to see if it was just bad caching data or something, but still no good. People seemed to have similar issues when using Resharper, but disabling that and clearing the cache on the computer that did have Resharper installed didn't fix it either.

    Since I know this is a common method as to how to assign ResourceKey's to templates/styles and I can't find anything on my specific problem, I figure I must be doing something wrong here. But no matter how simple I made the project or how many small changes I made to it, the problem persisted.


    Screenshot


    http://i.stack.imgur.com/e4A32.png


    Code

    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 Button}">
                <Setter Property="Background" Value="Black" />
                <Setter Property="Foreground" Value="White" />
                <Setter Property="Height" Value="24" />
            </Style>
    
            <Style x:Key="ButtonBaseStyleKeyThatWorks" TargetType="{x:Type Button}">
                <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 ButtonBaseStyleKeyThatWorks}" />
        </StackPanel>
    </Window>


    > Theme/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; }
            }
        }
    }


    Activity Log


      <entry>
        <record>603</record>
        <time>2016/05/12 01:13:06.978</time>
        <type>Error</type>
        <source>Editor or Editor Extension</source>
        <description>System.NullReferenceException: Object reference not set to an instance of an object.&#x000D;&#x000A;   at Microsoft.VisualStudio.Package.CompletionSet.OnCommit(String textSoFar, Int32 index, Int32 selected, UInt16 commitChar, String&amp; completeWord)&#x000D;&#x000A;   at Microsoft.VisualStudio.Editor.Implementation.ShimCompletion.TryCommit(Nullable`1 queryCommitChar, Boolean isSelected)&#x000D;&#x000A;   at Microsoft.VisualStudio.Editor.Implementation.ShimCompletionController.TryCommit(Nullable`1 commitChar)&#x000D;&#x000A;   at Microsoft.VisualStudio.Editor.Implementation.ShimCompletionController.PreProcessCommand(Guid&amp; pguidCmdGroup, UInt32 nCmdID, IntPtr pvaIn, IntPtr pvaOut)&#x000D;&#x000A;   at Microsoft.VisualStudio.Editor.Implementation.IntellisenseCommandFilter.Exec(Guid&amp; pguidCmdGroup, UInt32 nCmdID, UInt32 nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)&#x000D;&#x000A;   at Microsoft.VisualStudio.Editor.Implementation.CommandChainNode.InnerExec(Guid&amp; pguidCmdGroup, UInt32 nCmdID, UInt32 nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)&#x000D;&#x000A;   at Microsoft.VisualStudio.Editor.Implementation.CommandChainNode.Exec(Guid&amp; pguidCmdGroup, UInt32 nCmdID, UInt32 nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)&#x000D;&#x000A;   at Microsoft.VisualStudio.Editor.Implementation.BraceCompletionCommandFilter.Exec(Guid&amp; pguidCmdGroup, UInt32 nCmdID, UInt32 nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)&#x000D;&#x000A;   at Microsoft.VisualStudio.Editor.Implementation.CommandChainNode.InnerExec(Guid&amp; pguidCmdGroup, UInt32 nCmdID, UInt32 nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)&#x000D;&#x000A;   at Microsoft.VisualStudio.Editor.Implementation.CommandChainNode.Exec(Guid&amp; pguidCmdGroup, UInt32 nCmdID, UInt32 nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)&#x000D;&#x000A;   at Microsoft.VisualStudio.Editor.Implementation.CommandFilterWrapper.Exec(Guid&amp; pguidCmdGroup, UInt32 nCmdID, UInt32 nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)&#x000D;&#x000A;   at Microsoft.VisualStudio.Editor.Implementation.CommandChainNode.InnerExec(Guid&amp; pguidCmdGroup, UInt32 nCmdID, UInt32 nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)&#x000D;&#x000A;   at Microsoft.VisualStudio.Editor.Implementation.CommandChainNode.Exec(Guid&amp; pguidCmdGroup, UInt32 nCmdID, UInt32 nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)&#x000D;&#x000A;   at Microsoft.VisualStudio.Editor.Implementation.CommandFilterWrapper.Exec(Guid&amp; pguidCmdGroup, UInt32 nCmdID, UInt32 nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)&#x000D;&#x000A;   at Microsoft.VisualStudio.Editor.Implementation.CommandChainNode.InnerExec(Guid&amp; pguidCmdGroup, UInt32 nCmdID, UInt32 nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)&#x000D;&#x000A;   at Microsoft.VisualStudio.Editor.Implementation.CommandChainNode.Exec(Guid&amp; pguidCmdGroup, UInt32 nCmdID, UInt32 nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)&#x000D;&#x000A;   at Microsoft.VisualStudio.Package.ViewFilter.InnerExec(Guid&amp; guidCmdGroup, UInt32 nCmdId, UInt32 nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)&#x000D;&#x000A;   at Microsoft.VisualStudio.Package.ViewFilter.ExecCommand(Guid&amp; guidCmdGroup, UInt32 nCmdId, UInt32 nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)&#x000D;&#x000A;   at Microsoft.VisualStudio.DesignTools.Xaml.LanguageService.XamlLanguageService.XamlViewFilter.ExecCommand(Guid&amp; guidCmdGroup, UInt32 nCmdId, UInt32 nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)&#x000D;&#x000A;   at Microsoft.VisualStudio.Package.ViewFilter.Microsoft.VisualStudio.OLE.Interop.IOleCommandTarget.Exec(Guid&amp; guidCmdGroup, UInt32 nCmdId, UInt32 nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)&#x000D;&#x000A;   at Microsoft.VisualStudio.Editor.Implementation.CommandChainNode.InnerExec(Guid&amp; pguidCmdGroup, UInt32 nCmdID, UInt32 nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)&#x000D;&#x000A;   at Microsoft.VisualStudio.Editor.Implementation.SimpleTextViewWindow.Exec(Guid&amp; pguidCmdGroup, UInt32 nCmdID, UInt32 nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)&#x000D;&#x000A;   at Microsoft.VisualStudio.Editor.Implementation.VsKeyboardFilter.SendCommand(Guid cmdGroup, UInt32 cmdID, Object inParam)&#x000D;&#x000A;   at Microsoft.VisualStudio.Editor.Implementation.VsKeyboardFilter.TextInput(TextCompositionEventArgs args)&#x000D;&#x000A;   at Microsoft.VisualStudio.Text.Editor.Implementation.KeyProcessorDispatcher.&lt;&gt;c.&lt;DispatchTextInputEvents&gt;b__6_0(KeyProcessor p, TextCompositionEventArgs args)&#x000D;&#x000A;   at Microsoft.VisualStudio.Text.Editor.Implementation.KeyProcessorDispatcher.&lt;&gt;c__DisplayClass10_1`1.&lt;Dispatch&gt;b__0()&#x000D;&#x000A;   at Microsoft.VisualStudio.Text.Utilities.GuardedOperations.CallExtensionPoint(Object errorSource, Action call)</description>
      </entry>
    • Edited by Corylulu Thursday, May 12, 2016 11:12 PM
    Thursday, May 12, 2016 10:42 PM

Answers

  • Hi Corylulu,

    Thanks for your feedback and sharing your feedback link here.

    And I find that if I define a style for a TextBlock with the same operations, it works fine. So this problem seem just occurs with Button Style. I'm afraid that before this issue fixed, please copy and past the style key manually for Button Style. Other controls can still use the same way to assign the static resource.

    In addition, please mark your feedback link reply as answer, which can let other communities who has the same problem to see this feedback when open this thread. Please waiting for the response from report team patiently.

    Best Regards,
    Weiwei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Corylulu Tuesday, May 17, 2016 6:38 PM
    • Unmarked as answer by Corylulu Tuesday, May 17, 2016 11:52 PM
    • Marked as answer by Corylulu Wednesday, May 18, 2016 6:40 PM
    Monday, May 16, 2016 1:27 AM
    Moderator
  • Oh, I thought you meant along with a static resource key for the TextBlock. Yeah, I knew it only affected the types with static resource keys assigned, it's just in my current project I'm including a stylesheet that has these for just about every type. 

    My current workaround is to have a second stylesheet that replaces all the static keys with normal names and setting the build action to "DesignDataWithDesignTimeCreatableTypes" so the designer looks to that style sheet for building the resource list for intellisense. 
    Wednesday, May 18, 2016 6:40 PM

All replies

  • Hi Corylulu,

    According to your description, I create a sample project with your code snippet in both of Visual Studio 2015 with Update 2 and Visual Studio 2013 with Update 5. I get the same error as you mentioned.

    I suggest you submit this problem to Visual Studio Connect and share the feedback link here. I will vote your feedback and it also can let other communities who has the same problem to vote and add comments for this issue.

    I think the report team expert will treat this issue seriously. Thanks for your feedback for Visual Studio product.

    Best Regards,
    Weiwei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, May 13, 2016 5:41 AM
    Moderator
  • Yes, I did also submit the problem there as well 
    https://connect.microsoft.com/VisualStudio/feedback/details/2699457/setting-style-key-to-static-resourcekey-locks-up-intellisense-autocomplete-whenever-it-included-in-the-auto-listed-members

    At this point, I'm just trying to find a workaround for anyone who knows. Thanks for confirming the issue though.
    Friday, May 13, 2016 5:45 PM
  • Hi Corylulu,

    Thanks for your feedback and sharing your feedback link here.

    And I find that if I define a style for a TextBlock with the same operations, it works fine. So this problem seem just occurs with Button Style. I'm afraid that before this issue fixed, please copy and past the style key manually for Button Style. Other controls can still use the same way to assign the static resource.

    In addition, please mark your feedback link reply as answer, which can let other communities who has the same problem to see this feedback when open this thread. Please waiting for the response from report team patiently.

    Best Regards,
    Weiwei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Corylulu Tuesday, May 17, 2016 6:38 PM
    • Unmarked as answer by Corylulu Tuesday, May 17, 2016 11:52 PM
    • Marked as answer by Corylulu Wednesday, May 18, 2016 6:40 PM
    Monday, May 16, 2016 1:27 AM
    Moderator
  • I just tested this with a TextBlock and TextBox and both resulted in the same problem. Are you sure it worked after it was rebuilt? How was it populating in intellisense? 
    Tuesday, May 17, 2016 11:53 PM
  • Hi Corylulu,

    Yes, if I add a new style which is target for TextBlock in my Window Resource. Then I try use it for my TextBlock, it will show as below screenshot and I can choose it through the direction keys. I'm using Visual Studio Enterprise 2015 Update 2. Just the Button style has the same result with yours.

    Best Regards,
    Weiwei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, May 18, 2016 6:16 AM
    Moderator
  • Oh, I thought you meant along with a static resource key for the TextBlock. Yeah, I knew it only affected the types with static resource keys assigned, it's just in my current project I'm including a stylesheet that has these for just about every type. 

    My current workaround is to have a second stylesheet that replaces all the static keys with normal names and setting the build action to "DesignDataWithDesignTimeCreatableTypes" so the designer looks to that style sheet for building the resource list for intellisense. 
    Wednesday, May 18, 2016 6:40 PM