Description
- .NET Core Version 3.0.100-preview-010184
- Windows version: Server 2019, 17763.253
- Does the bug reproduce also in WPF for .NET Framework 4.8?: No
I am porting a WPF control library to .NET Core. In this library, they define many const
fields that they use in attributes, element names, etc. For example:
[TemplateVisualState(Name = MyState, GroupName = MyStateGroup)]
class MyControl : Control
{
public const String MyState = "MyState";
public const String MyStateGroup = "MyStateGroup";
}
<!-- somewhere inside of a control template -->
<VisualStateGroup Name="{x:Static local:MyControl.MyState}">...</VisualStateGroup>
The .NET Framework tooling works fine here. However, in .NET Core, trying to compile code using this pattern produces this error:
error MC3079: MarkupExtensions are not allowed for Uid or Name property values, so '{x:Static local:MyControl.MyState}' is not valid.
Here's a small repro that demonstrates this issue. The application will compile fine if you set the target framework to net472
, but it will not compile with the above error if you set it to netcoreapp3.0
.
Note that this pattern doesn't work in all cases; I don't know the specifics on where it does and doesn't work, but I think it only works for files evaluated at runtime.