Ok so I have a WPF DataGrid bound to a collection of Products. The Product class has a property called ParentNumber and two navigation properties, Product Parent
and ICollection<Product> SubProducts
.
I want to indicate in my DataGrid with a small image what products are children and what products are parents.
In my DataGrid I have a column with two images. The first image has its visibility property bound to the parentNumber with a Converter that returns System.Windows.Visibility.Visible if the parentNumber is not null. That part was easy.
So my question is how I can do the same for the parent product? What do I bind to? Do I need to add another property in my class? What is the best way to do this?
I have implemented the INotifyPropertyChanged on all the properties in the Product class.
Here is the code:
<DataGridTemplateColumn Header="Productnr" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Height="16"
Margin="0,0,5,0"
Source="{StaticResource ChildImage}"
Visibility="{Binding Path=IsChild,
Mode=OneWay,
Converter={StaticResource BoolToVisibilityConverter}}" />
<Image Height="16"
Margin="0,0,5,0"
Source="{StaticResource ParentImage}"
Visibility="{Binding ???? />
<TextBlock Text="{Binding Path=ProductNumber}" />
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
public class Product : INotifyPropertyChanged
{
public string ProductNumber { get; set; }
public string ParentNumber
{
get
{
return _parentNumber;
}
set
{
_parentNumber = value;
OnPropertyChanged("ParentNumber");
}
}
public virtual Product Parent { get; set; }
public virtual ICollection<Product> SubProducts
{
get
{
return _subProducts;
}
set
{
_subProducts = value;
OnPropertyChanged("SubProducts");
}
}
...
}