c# WPF AlternateContent doesn't exist in the Namespace […]

女生的网名这么多〃 提交于 2019-12-02 04:25:30

问题


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:


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.



来源:https://stackoverflow.com/questions/43362985/c-sharp-wpf-alternatecontent-doesnt-exist-in-the-namespace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!