Created
June 23, 2011 20:54
-
-
Save jrwren/1043608 to your computer and use it in GitHub Desktop.
nasty DP hax for databinding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void GlobalVariablesGrid_ColumnFix() | |
{ | |
foreach (var column in GlobalVariablesGrid.Columns) | |
{ | |
if ("Name".Equals(column.Header)) | |
{ | |
var dpd = System.ComponentModel.DependencyPropertyDescriptor.FromProperty(DataGridColumn.WidthProperty, typeof(DataGridColumn)); | |
if (dpd != null) | |
{ | |
Logger.Debug("wiring AddValueChanged for " + dpd); | |
dpd.AddValueChanged(column, (o, ea) => { | |
var width = dpd.GetValue(column); | |
Logger.Debug("Width changed for " + o + " " + ea + " " + column+" to "+width); | |
var columndatacontextdp = System.ComponentModel.DependencyPropertyDescriptor.FromProperty(FrameworkElement.DataContextProperty, typeof(DataGridColumn)); | |
if (null == columndatacontextdp) | |
Logger.Debug("could not find columndatacontextdp"); | |
else{ | |
var columnDataContext = columndatacontextdp.GetValue(column); | |
Logger.Debug("column (" + column + ") datacontext found " + columnDataContext); | |
} | |
}); | |
}else | |
dpd = System.ComponentModel.DependencyPropertyDescriptor.FromProperty(DataGridColumn.ActualWidthProperty, typeof(DataGridColumn)); | |
if (dpd != null) | |
{ | |
Logger.Debug("wiring AddValueChanged for " + dpd); | |
dpd.AddValueChanged(column, (o, ea) => | |
{ | |
Logger.Debug("ActualWidth changed for " + o + " " + ea + " " + column); | |
//TODO: finish impl similar to above. | |
}); | |
} | |
} | |
else if (column.Header as string == "Value") | |
{ | |
//TODO: impl like for teh Name column | |
} | |
Binding binding = (column as DataGridBoundColumn).Binding as Binding; | |
binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment