Search code examples
c#wpfxamlsystemcolors

SystemColor is missing InactiveSelectionHighlightTextBrushKey


After editing a ControlTemplate in a prototype project, I decided to move the custom ControlTemplate to my main project. This didn't work out of the box as expected, Visual Studio notified me of the following error:

Error Cannot find the static member 'InactiveSelectionHighlightBrushKey' on the type 'SystemColors'.

There was no highlight and warning in the xaml source, so it was not clear what was wrong. Going to the definition of 'InactiveSelectionHighlightBrushKey', I did not see the entry in the SystemColors members list:

enter image description here

I did find the member in the object browser of my prototype project. How come the SystemColors class is incomplete in my main project?


Solution

  • Based on this comment I started looking for a difference in the framework version.

    For some reason, even though the project was TargetFramework was set to '.NET Framework 4.5.2' in the properties, the references paths of PresentationFramework.dll and WindowsBase.dll were pointing to the /v4.0 path. Changing the target from 4.0 to 4.5.2 in the properties had no effect. I had to remove and add the references manually.

    A git diff on the .csproj shows the following changes:

    -    <Reference Include="PresentationFramework">
    -      <HintPath>..\..\..\..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\PresentationFramework.dll</HintPath>
    -    </Reference>
    +    <Reference Include="PresentationFramework" />
    

    Same for WindowsBase.dll. The explicit definition of HintPath probably caused the DLL references not to change from path version.