c# WPF AlternateContent doesn't exist in the N

2019-02-28 10:18发布

I am facing the need to have XAML Code only in design-time. I have found a nice Solution to this, which can be found here. It seems like there are a few guys having a Problem with the parse-timing of XmlnsDefinitionAttribute which is solved here.

In my case the issue is really, that I cannot compile my code, because AlternateContent can't be found in the namespace xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006". I haven't found any documentation to this namespace indeed and it seems strange, that the line mc:Ignorable="d"doesn't fail to build, which means I have at least one assembly containing the above namespace.

This is my Code:

#if DEBUG
[assembly: XmlnsDefinition("debug-mode", "MyNamespace")]
#endif

<Window x:Class="MyNamespace.SomeWindow"
        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:debug="debug-mode"
        mc:Ignorable="d"
        ... >
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <mc:AlternateContent>
                    <mc:Choice Requires="debug">
                        <ResourceDictionary Source="pack://application:,,,/Styles;component/Generic.xaml" />
                    </mc:Choice>
                </mc:AlternateContent>
                ...
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    ...
</Window>

My guess is, that I'm missing an Assembly-Reference, but I've not yet found a Documentation specifying a containing Assembly for AlternateContent. Do you have any ideas how I might get this to work?

Edit:

It seems like this is a common VS Problem which can be solved by this mc:Ignorable="d mc". This just doesn't work in my case, because I would need this to include Resources at Design-Time, which should be available to the VS-Designer :)

1条回答
看我几分像从前
2楼-- · 2019-02-28 10:54

It seems like this is a common VS problem which can be solved by this code

mc:Ignorable="d mc"

This must be added to the root element of the view.
Note: that you already should have mc:Ignorable="d" in your root element, so you have to just add the mc to it.

查看更多
登录 后发表回答