I am refactoring the code from sample:
And after excluding Skills class, with corresponding changes in
in MainWindow.xaml
<local:Team>
<local:Employee Name="Larry" Age="21">
<local:Employee.Skills>
<!-- local:Skills -->
<local:Skills>
in MainWindow1.xaml.cs:
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
namespace WpfApplication
{
public class Skill
{//I'd like to exclude class Skill having moved it into class Employee as nested one
public string Description { get; set; }
}
public class Employee
{
public string Name { get ; set; }
public int Age { get; set; }
public List<Skill> Skills { get; set; }
public Employee()
{
Skills=new List<Skill>();
}
/*class Skill
{
public string Description { get; set; }
} */
}
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();
}
}
}
How should I change Window1.XAML if to move:
Skill
class into Employee
class in Window1.xaml.cs?
based on the same code:
Update (answering 1st RV1987's comment):
Answers tp Creating an instance of a nested class in XAML tell that it is possible but unclear how to use:
another answer by townsean is based on citation from msdn:
"Your custom class must not be a nested class. Nested classes and the "dot" in their general CLR usage syntax interfere with other WPF and/or XAML features such as attached properties."
But, it is in general, and for "your custom class" but in in my concrete code attached to this question there are dozens "dots" (like Employee.Skills
) and it is not my custom class that is nested but my custom class has nested class inside.
Update2 (answering 2nd RV1987's comment-question):
Yes, I've just tried that + approach, which does not work, but:
Unfortunately, what you want to do is not possible in XAML (from MSDN):
Your custom class must not be a nested class. Nested classes and the "dot" in their general CLR usage syntax interfere with other WPF and/or XAML features such as attached properties.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With