I'm trying to recreate 10. Instantiate a class in XAML
Here's the Xaml snippet from the example: -
<Grid.Resources>
<!-- Create a array of Person objects -->
<x:Array x:Key="Office" Type="{x:Type local:Person}">
<!-- Instantiate a Person and add to the array -->
<local:Person Name="Michael" Age="40"/>
<local:Person Name="Jim" Age="30"/>
<local:Person Name="Dwight" Age="30"/>
</x:Array>
</Grid.Resources>
Here's the code-behind snippet: -
public class Person {
public string Name { get; set; }
public int Age { get; set; }
}
I've started to create a Visual Studio C# WPF 2015 project with this Xaml:-
<Window x:Class="AdvFlow1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:AdvFlow1"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.Resources>
<!-- Create a array of Person objects -->
<x:Array x:Key="Office" Type="{x:Type local:Person}">
<!-- Instantiate a Person and add to the array -->
<local:Person Name="Michael" Age="40"/>
<local:Person Name="Jim" Age="30"/>
<local:Person Name="Dwight" Age="30"/>
</x:Array>
</Grid.Resources>
</Grid>
</Window>
and this code-behind: -
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace AdvFlow1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
}
}
I'm getting an error from Type="{x:Type local:Person}" "The name "Person" does not exist in the namespace "clr-namespace:AdvFlow1".
I'm fairly newbie but already have no hair left.
Thanks, Paul.