I have a custom object that has a handful of properties and a ObservableCollection
.
The problem I'm having is getting them to all play nicely. It seems I'd like a CollectionViewSource
to filter but I cant figure out how that applies so that I can run the filter on the code side.
I havent been able to find a good example of binding like this that takes in to account multiple things (proeprties on the main object, a collection with a filter)
class Student
{
public string Name { get; set; }
public DateTime DOB { get; set; }
public ObservableCollection<ClassRoom> Classes { get; set; }
public Student()
{
this.Classes = new ObservableCollection<ClassRoom>();
}
}
class ClassRoom
{
public string Name { get; set; }
public int Room { get; set; }
}
using that, i do this in the main.cs
var student = new Student { Name = "Justin", DOB = new DateTime(1983, 6, 15) };
student.Classes.Add(new ClassRoom { Name = "math", Room = 102});
student.Classes.Add(new ClassRoom { Name = "english", Room = 119 });
this.DataContext = student;
so i can then do this in xaml
<TextBlock Grid.Row="0" Grid.Column="0">
<Run Text="Name: "/>
<Run Text="{Binding Name}"/>
</TextBlock>
<TextBlock Grid.Row="0" Grid.Column="1">
<Run Text="DOB: "/>
<Run Text="{Binding Name}"/>
</TextBlock>
<DataGrid Grid.Row="1" Grid.ColumnSpan="2" Grid.Column="0"
ItemsSource="{Binding Classes}" AutoGenerateColumns="True"></DataGrid>
I really just want to create the CVS against the Classes property, so that way i can assign the CSV to the DataGrid
and deal with custom column bindings with just Binding Room
rather then Binding Classes.Room
at least i suspect, basically the issue is i couldnt find any example/tutorials that talk about mixing a OC with other data.