可能重复:
如何在 WPF XAML 中使用嵌套类?
我正在重构示例中的代码:
- 24.129.21。C# / CSharp Tutorial » Windows Presentation Foundation » Binding
中的Master Detail Binding)
并且在排除 Skills 类之后
,
在MainWindow.xaml中进行了相应的更改
<local:Team>
<local:Employee Name="Larry" Age="21">
<local:Employee.Skills>
<!-- local:Skills -->
<local:Skills>
我在MainWindow1.xaml.cs:
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
namespace WpfApplication
{
public class Skill
{//I'd like to remove class Skill having moved property string Description into class Employee
public string Description { get; set; }
}
public class Employee
{
public string Name { get ; set; }
public int Age { get; set; }
//I'd like to change in the next line Skill --> String
public List<Skill> Skills { get; set; }
//public List<String> Skills { get; set; }
public Employee()
{
//I'd like to change in the next line Skill --> String
Skills=new List<Skill>();
//Skills=new List<string>();
}
}
public class Team : ObservableCollection<Employee> { }
public class Company
{
public string CompanyName { get ; set; }
public Team Members { get ; set; }
}
public class Companies : ObservableCollection<Company> { }
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
}
}
如果要更改,我应该如何更改 Window1.XAML:
List<Skill>
到List<String>
在 Window1.xaml.cs 中?
基于相同代码的相关问题:
更新:
只是要注意我尝试过的错误:
- "A" 而不是 A(不带引号);
- 它应该是
String
(但不是string
)在 XAML 中(而在 C# 中是string
orString
) - 根据现有代码,尝试将 A 作为属性放置在一个标记中,
<sys:String />
而不是:<sys:String>A</sys:String>