Click here to Skip to main content
14,738,276 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a DataGrid with ComboBoxes. The data binding works fine with simple types but not with properties within types. Specifically:

<DataGrid ...>
...
<DataGridComboBoxColumn SelectedValueBinding="{Binding Path=TimeInterval.Start}" ....
<DataGridComboBoxColumn.ElementStyle>
<Style TargetType="ComboBox">
<Setter Property="ItemsSource Value="{Binding Path=data .....
<DataGridComboBoxColumn.EditingElementStyle>.......


Here

class Shift { .... public TimeInterval TimeInterval {get {...} set {...}} public int ShiftSize { get {...} set {..}}}

class TimeInterval { public double Start { get {...} set {...}}


This doesn't work. But if I change TimeInterval.Start to ShiftSize it works OK.

NOTE also that within a ListView,
<TextBlock Text="{Binding Path=TimeInterval.Start ....

also works fine.

Any ideas?? Thanks!!
Posted
Comments
Pheonyx 30-Sep-13 11:56am
   
I suspect the issue is because TimeInterval does not implement INotifyPropertyChanged, this is required so that if changes are made then the property updates and then informs the binding it's data has changed triggering a refresh.

The TextBlock binding is a read only binding, i.e. data is not being written back so there is no need for the change refresh to occur.

I could be wrong but I suspect your issue is something to do with this.
Julio Kuplinsky 30-Sep-13 14:39pm
   
Yes it does. I tried to keep my post simple. In fact I have

public TimeInterval TimeInterval
{
get
{
return timeInterval;
}
set
{
timeInterval = value;
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("TimeInterval"));
}
}
Pheonyx 30-Sep-13 14:45pm
   
The TimeInterval property may do, but does the TimeInterval object implement it, e.g. its start setting etc).
Julio Kuplinsky 30-Sep-13 15:24pm
   
yes; like i say in my original post, it works with a listview/textblock
Marvin Ma 1-Oct-13 3:18am
   
It's not the solution to your Problem but a little tip:
You could source out the if-statement in a method, so you save some writing work.

E.g:
public void NotifyPropertyChanged(string propertyname)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyname));
}
}

Then in your setter, you could just call NotifyPropertyChanged("YourProperty");
Julio Kuplinsky 1-Oct-13 12:11pm
   
thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900