AlternateContent Tags causing issues with IDE, but

2020-03-01 06:23发布

问题:

I am working on a legacy product. I need to make regions of a complex UI optional, based on build constants. It is not feasible to move these regions into controls, so I am using AlternateContent Tags (mc:AlternateContent).

This works perfectly, at compilation and the application runs as expected.

However, the IDE claims one error for each AlternateContent, and enclosed Choice Tag, and will not load the Design window/preview (in VS or Blend):

The name "AlternateContent" does not exist in the namespace "http://schemas.openxmlformats.org/markup-compatibility/2006"
The name "Choice" does not exist in the namespace "http://schemas.openxmlformats.org/markup-compatibility/2006"

I have tried, rebuilding, cleaning and rebuilding, changing build settings between release, debug, x86, x64, and rebooting. Nothing helps. It even give the same errors in Blend.

I am hoping that this is just something stupid that I am doing, and I can fix it; or possibly a newer Namespace URI I should be using. If I cannot resolve the errors, I am hoping someone knows a trick to suppress these errors in the IDE, so can use it.

I have a fully updated VS2013 Premium installation. However, It has the glitch on a test machine running VS14 CTP, and another running VS2012 (fully updated), both without any add-ins; so I have to assume it is not a problem with my PCs install.

回答1:

A little late to the party, but if you add the mc tag to your Ignorable attribute the error goes away. Your content won't show in the designer but worked for me when I compiled the different flavours of my project.

<UserControl...
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:conditional="defined-in-assembly.cs"
    mc:Ignorable="d mc"/>


回答2:

What about this:

public class BuildConstants
{
    public bool IsDebug
    {
        get
        {
#if DEBUG
            return true;
#else
            return false;
#endif
        }
    }
}

and the xaml:

<Application.Resources>
    <BooleanToVisibilityConverter x:Name="BooleanToVisibilityConverter"></BooleanToVisibilityConverter>
    <l:BuildConstants x:Key="BuildConstants" />
</Application.Resources>

<Grid Visibility="{Binding IsDebug, Source={StaticResource BuildConstants}, Converter={StaticResource BooleanToVisibilityConverter}}">
    <TextBlock Text="This will be visible only when DEBUG build constant is present"></TextBlock>
</Grid>