【问题标题】:c# WPF AlternateContent doesn't exist in the Namespace [...]c# WPF AlternateContent 在命名空间中不存在 [...]
【发布时间】:2018-10-03 21:30:31
【问题描述】:

我面临着仅在设计时拥有 XAML 代码的需要。我找到了一个很好的解决方案,可以找到here。似乎有些人对XmlnsDefinitionAttribute 的解析时间有疑问,here 已解决。

就我而言,问题确实是我无法编译我的代码,因为在命名空间xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 中找不到AlternateContent。我确实没有找到这个命名空间的任何文档,而且看起来很奇怪,mc:Ignorable="d" 行没有构建失败,这意味着我至少有一个包含上述命名空间的程序集。

这是我的代码:

#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>

我的猜测是,我缺少一个 Assembly-Reference,但我还没有找到一个文档指定包含 AlternateContent 的 Assembly。你有什么想法可以让this 工作吗?

编辑:

这似乎是一个常见的 VS 问题,可以通过 mc:Ignorable="d mc" 解决。这在我的情况下不起作用,因为我需要它在设计时包含资源,VS-Designer 应该可以使用它:)

【问题讨论】:

  • 看看this。基本上,尝试将mc 添加到Ignorabletag
  • @Pikoh 如果我不需要这些东西可供设计师使用,这将起作用。
  • 我不明白你为什么拒绝我的编辑。 AlternateContext 真的是 WPF 中的东西吗?我找不到任何关于它的参考资料。
  • @polfosol 我的错,我一定是在无尽的代码天空中的某个地方迷失了方向:) - 当然它应该到处都是AlternateContent
  • 没问题!但是,标题仍然是最重要的部分,因为它会影响搜索结果。请也解决这个问题。

标签: c# wpf xaml xml-namespaces


【解决方案1】:

这似乎是一个常见的VS问题,可以通过这段代码解决

mc:Ignorable="d mc"

这必须添加到视图的根元素中。
注意:您的根元素中应该已经有mc:Ignorable="d",因此您只需将mc 添加到它。

【讨论】:

    猜你喜欢
    • 2014-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-08
    • 2016-07-26
    • 2011-05-03
    • 1970-01-01
    • 2011-10-19
    相关资源
    最近更新 更多