属性“FactoryMethod”; XML 命名空间中不存在“http://schemas.microsoft.com/winfx/2006/xaml”
我是 WPF 和 XAML 的新手,我已经开始后悔尝试学习它们了。我不知道为什么运行下面的代码会出错,我直接从WPF 4 unleashed书中复制了它。如果你们中有人能帮我解决这个问题,我将欠你们一个大人情:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:System="clr-namespace:System;assembly=mscorlib"
xmlns:collections="clr-namespace:System.Collections;assembly=mscorlib"
xmlns:Person="clr-namespace:Src"
Title="MainWindow" Height="354" Width="525">
<StackPanel>
<Label Name="lblText" Foreground="BlanchedAlmond" FontWeight="Bold" FontSize="20">
Test
</Label>
<Label x:FactoryMethod="System:Guid.NewGuid">Test2</Label>
<ListBox SelectionChanged="ListBox_SelectionChanged">
<Person:Person FirstName="Deepak" LastName="Sharma"></Person:Person>
<Person:Person FirstName="Nidhi" LastName="Sharma"></Person:Person>
</ListBox>
</StackPanel>
</Window>
I am complete newbie to WPF and XAML and I am already regretting trying to learn it in the first place. I am not sure why the error in running the code below, I copied it directly from a WPF 4 unleashed book. If any of you guys can help me in figuring this our I will owe you guys a big favor:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:System="clr-namespace:System;assembly=mscorlib"
xmlns:collections="clr-namespace:System.Collections;assembly=mscorlib"
xmlns:Person="clr-namespace:Src"
Title="MainWindow" Height="354" Width="525">
<StackPanel>
<Label Name="lblText" Foreground="BlanchedAlmond" FontWeight="Bold" FontSize="20">
Test
</Label>
<Label x:FactoryMethod="System:Guid.NewGuid">Test2</Label>
<ListBox SelectionChanged="ListBox_SelectionChanged">
<Person:Person FirstName="Deepak" LastName="Sharma"></Person:Person>
<Person:Person FirstName="Nidhi" LastName="Sharma"></Person:Person>
</ListBox>
</StackPanel>
</Window>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
x:FactoryMethod
是一个 XAML 2009 功能,根据文档,该功能不受支持在标记编译的 XAML 中。除此之外,
Guid.NewGuid
不会返回Label
,所以我不确定这首先应该如何解决。x:FactoryMethod
is a XAML 2009 feature, which according to the documentation are not supported in markup compiled XAML.Besides that
Guid.NewGuid
does not return aLabel
so i am not sure how this is supposed to work out in the first place.HB的回答是准确的。既然您说您正在阅读 WPF4 Unleashed,请参阅从第 67 页开始的页表 2.2。
以下是 MSDN 对此的说明:
“在 WPF 中,您可以使用 XAML 2009 功能,但仅限于未标记编译的 XAML。WPF 的标记编译 XAML 和 XAML 的 BAML 形式当前不支持 XAML 2009 关键字和功能。”
参考此处 和 此处。
H.B's answer is accurate. Since you said you're reading WPF4 Unleashed, refer to page table 2.2 starting on page 67.
Here is what MSDN has to say about it:
"In WPF, you can use XAML 2009 features but only for XAML that is not markup-compiled. Markup-compiled XAML for WPF and the BAML form of XAML do not currently support the XAML 2009 keywords and features."
Reference here and here.