开发者

The attribute 'FactoryMethod' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml'

开发者 https://www.devze.com 2023-03-24 14:32 出处:网络
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 unleash

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
    </开发者_JAVA百科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>


x:FactoryMethod is a XAML 2009 feature, which according to the documentation are not supported in markup compiled XAML.

In WPF, you can use XAML 2009 features, but only for XAML that is not WPF markup-compiled. Markup-compiled XAML and the BAML form of XAML do not currently support the XAML 2009 language keywords and features.

Besides that Guid.NewGuid does not return a Label so i am not sure how this is supposed to work out in the first place.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消