How can I use XAML 2009 as design data in Visual Studio?
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?
"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.
精彩评论