I want to bind the object Info in my xaml column:
<DataGridTextColumn Width="200" Binding="{Binding Path=Message.Info.InfoName, Mode=OneWay, TargetNullValue=No Information available}">
<DataGridTextColumn.Header>
<Label>Information</Label>
</DataGridTextColumn.Header>
</DataGridTextColumn>
For each message I've a constructor and in the same message class I've this property:
public IMessageInformation Info
{
get
{
//if (_info == null)
// return "no info available";
return _info;
}
set
{
_info = value;
NotifyPropertyChanged("Info");
}
}
Now, for each message the WPF column should display either the name of the information (gets from the object Info (Info.InfoName property)) or if the message has no information (other type) it should display "No Info available".
If there is no information available I get no object (Info == null).
My problem:
- If the message has information the property Info gets an object with the name and the Binding works
- If the message has no information the property Info gets no object and the column is empty.
What I've tried:
I've tried to insert an if statement into the Info property (getter). The statement works but of course I can't return a string if the property expects the return type object info.
And my other approach TargetNullValue=No Information available} doesn't work too.