I have the following sample data, which works out nicely...
<SampleData:DashboardViewModel xmlns:SampleData="clr-namespace:MyApp.ViewModels">
<SampleData:DashboardViewModel.Employees>
<SampleData:EmployeeViewModel FirstName="Aaron" "Adams" />
<SampleData:EmployeeViewModel FirstName="Billy" "Bob" />
<SampleData:EmployeeViewModel FirstName="Charlie" "Chaplin" />
</SampleData:DashboardViewModel.Employees>
</SampleData:DashboardViewModel>
However, I find that it would be useful to be able to reuse that list of sample employees instead of retyping it every time. I can not figure out how to reuse that list. Basically, I want to have another SampleData file (SampleEmployees.xaml) which contains that list of employees, then be able to include that in my other samples...
<SampleData:DashboardViewModel xmlns:SampleData="clr-namespace:MyApp.ViewModels">
<SampleData:DashboardViewModel.Employees ... /> <!-- What goes in there? -->
</SampleData:DashboardViewModel>
<SampleData:OtherViewModel xmlns:SampleData="clr-namespace:MyApp.ViewModels">
<SampleData:OtherViewModel.Employees ... /> <!-- What goes in there? -->
</SampleData:OtherViewModel>
Also, how to create the list separately in another XAML file??
ViewModel:
public class DashboardViewModel : NotificationObject
{
public class DashboardViewModel(IDataService dataService)
{
InternalEmployees = new ObservableCollection<EmployeeViewModel>(dataService.GetEmployees());
Employees = new ReadOnlyObservableCollection<EmployeeViewModel>(InternalEmployees);
}
private ObservableCollection<EmployeeViewModel> InternalEmployees { get; set; }
public ReadOnlyObservableCollection<EmployeeViewModel> Employees { get; private set; }
}