如何在 Visual Studio 中使用 XAML 2009 作为设计数据?

发布于 2024-11-02 00:27:11 字数 1698 浏览 1 评论 0原文

我有一个 xaml 文件,我想将其用作 DesignData(具有设计时可创建类型)。 我还想在其中使用 XAML 2009 功能,但是 Visual Studio 似乎不接受它,抱怨我想要使用的属性在目标命名空间中不存在。

这是我的 xaml 文件的样子:

<my:ViewModel 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib"
    xmlns:my="clr-namespace:MyCompany"
>
    <my:ViewModel.ViewCollection>
        <!-- That part does not work, because it tells me that FactoryMethod and Arguments could not be found in the namespace for prefix 'x'. -->
        <my:BusinessObjectView x:FactoryMethod="my:BusinessObjectView.Convert">
            <x:Arguments>
                <my:BusinessObject />
            </x:Arguments>
        </my:BusinessObjectView>
    </my:ViewModel.ViewCollection>
    <my:ViewModel.BoCollection>
        <!-- Even though the x:TypeArguments syntax for defining objects only appears in XAML 2009, that part works fine - probably because the TypeArguments attribute already existed in that namespace. -->
        <scg:List x:TypeArguments="my:BusinessObject">
            <my:BusinessObject />
        </scg:List>
    </vm:ViewModel.BoCollection>
</my:ViewModel>

这是 XML 项目文件中描述构建操作的片段:

<DesignDataWithDesignTimeCreatableTypes Include="Path/To/File.xaml">
  <SubType>Designer</SubType>
  <Generator>MSBuild:Compile</Generator>
</DesignDataWithDesignTimeCreatableTypes>

那么,问题是什么? 是命名空间前缀吗? (在这种情况下,我应该为 XAML 2009 使用哪一个?) 这是构建操作吗? 我的整个方法有缺陷吗?

I have a xaml file which I want to use as DesignData (with design-time creatable types).
I also want to use XAML 2009 features in it, however Visual Studio does not seem to accept it, complaining that the attributes I want to use do not exist in the target namespace.

Here is what my xaml file looks like:

<my:ViewModel 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib"
    xmlns:my="clr-namespace:MyCompany"
>
    <my:ViewModel.ViewCollection>
        <!-- That part does not work, because it tells me that FactoryMethod and Arguments could not be found in the namespace for prefix 'x'. -->
        <my:BusinessObjectView x:FactoryMethod="my:BusinessObjectView.Convert">
            <x:Arguments>
                <my:BusinessObject />
            </x:Arguments>
        </my:BusinessObjectView>
    </my:ViewModel.ViewCollection>
    <my:ViewModel.BoCollection>
        <!-- Even though the x:TypeArguments syntax for defining objects only appears in XAML 2009, that part works fine - probably because the TypeArguments attribute already existed in that namespace. -->
        <scg:List x:TypeArguments="my:BusinessObject">
            <my:BusinessObject />
        </scg:List>
    </vm:ViewModel.BoCollection>
</my:ViewModel>

And here is the fragment in the XML project file that describes the build action:

<DesignDataWithDesignTimeCreatableTypes Include="Path/To/File.xaml">
  <SubType>Designer</SubType>
  <Generator>MSBuild:Compile</Generator>
</DesignDataWithDesignTimeCreatableTypes>

So, what is the problem?
Is it the namespace prefix? (In which case, which one should I use for XAML 2009?)
Is it the build action?
Is my whole approach flawed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

山有枢 2024-11-09 00:27:11

“松散 XAML 文件”是一个与 XAML 2009 的概念正交的概念。
松散 XAML 文件是在运行时加载的纯 XAML(无代码隐藏)文件。 http://wpf.2000things.com/2010/10/ 20/100-松散-xaml-文件/
XAML 2009 是 XAML 语言的一个版本和一组相应的架构。

要使 .xaml 文件“松散”,您只需停止编译它(在文件属性中)。
要加载松散的 .xaml 文件,您需要使用 XamlReader.Load 方法 http://msdn.microsoft.com/en-us/library/system.windows.markup.xamlreader.load.aspx http://www.c-sharpcorner .com/uploadfile/37db1d/understanding-uncompiled-xaml-to-design-dynamic-ui-in-wpf/
奇怪的是,XAML2009 文件似乎仍然使用 2006 架构。

"Loose XAML file" is a concept which is orthogonal to the concept of XAML 2009.
Loose XAML file is a XAML-only (no code behind) file which is loaded at run-time. http://wpf.2000things.com/2010/10/20/100-loose-xaml-files/
XAML 2009 is an version of the XAML language and a set of corresponding schemas.

To make .xaml file "loose" you just need to stop it being compiled (in file properties).
To load loose .xaml file you need to use XamlReader.Load Method http://msdn.microsoft.com/en-us/library/system.windows.markup.xamlreader.load.aspx http://www.c-sharpcorner.com/uploadfile/37db1d/understanding-uncompiled-xaml-to-design-dynamic-ui-in-wpf/
Strangely it seems that XAML2009 files still use the 2006 schemas.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文