WPF - gdzie wstawić <local: ... >?

0

Witam.

Zaczynam naukę WPF'a z książką "Pro WPF in C# 2010", i już w 2 rozdziale złapały mnie błędy.
Każą utworzyć klasę Person (którą posiadam), i dodać do XAML:

<local:Person>
<x:Arguments>
<x:String>Joe</x:String>
<x:String>McDowell</x:String>
</x:Arguments>
</local:Person> 

Tylko za diabła nie mam gdzie tego włożyć. Pomiędzy <Windows></Windows> pisze, że: The property 'Content' is set more than once., co rozumiem, bo jest Grid. Do środka grida też nie pasuje bo nie jest typem UIElementCollection. Przed <Windows> tworzy błędy o nie istnieniu local:Person, a za </Windows> 'There are multiple root elements.
Posiadam najprostsze okno z WPF, z Windowsem i Gridem, niczego więcej nie ma.

0

Wstaw to w Resourcach Okna.

0

Tak to wygląda u mnie:


<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"          
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfApplication1"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        Title="MainWindow" Height="300" Width="300">
    <Window.Resources>
        <local:Person>
            <x:Arguments>
                <x:String>Joe</x:String>
                <x:String>McDowell</x:String>
            </x:Arguments>
        </local:Person>
    </Window.Resources>
    <Grid>
        
    </Grid>

</Window>
 

Wyskakuje 6 błędów.

0

a nie łaska tak napisać jakich..?

0

Błędy:
Unrecognized tag 'x:Arguments' in namespace 'http://schemas.microsoft.com/winfx/2006/xaml'.
Type 'Person' is not usable as an object element because it is not public or does not define a public parameterless constructor or a type converter.
2x
The type 'x:String' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
The type 'x:Arguments' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
All objects added to an IDictionary must have a Key attribute or some other type of key associated with them.

Kod klasy Person:

    public class Person
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public Person(string firstName, string lastName)
        {
            FirstName = firstName;
            LastName = lastName;
        }
    }
0

dwie najwazneijsze rzeczy do rozwiazania na poczatek, to:

All objects added to an IDictionary must have a Key attribute or some other type of key associated with them.

kazda rzecz wstawiona do 'resources' musi miesc nadany atrybut x:Key="zxcxzczxczx", inaczej nie bedziesz mial jak sie do niej dostac.

Unrecognized tag 'x:Arguments' in namespace 'http://schemas.microsoft.com/winfx/2006/xaml'.

a ten fakt generuje Ci cala reszte bledow..
na poczatek, sprawdz czy Twoj build-target-framework jest ustawiony na .Net4.0, nie wiem czemu byś miał mieć, ale możesz masz ustawiony 3.5?

0

Ok, rzecz z x:Key załatwiona.
Co do target-frameworku to jest ustawiony na 4.0.

1 użytkowników online, w tym zalogowanych: 0, gości: 1