I am dynamically generating most of the fields in a XamDataGrid with unbound fields. I use the CellsInViewChanged event to get all uninitialized CVP's and set a binding on the Value property.
cvp.SetBinding(CellValuePresenter.ValueProperty, binding);
Initially, the binding works and gets the initial value, however changes to the binding to not update the CVP. I bound a text box in the exact same manner and it is updating.
I also notice that the bindingexpressiong.status is immediately detached for some reason.
Window window = new Window();
TextBlock block = new TextBlock();
block.Width = 100;
block.Height = 100;
window.Content = block;
window.SizeToContent = SizeToContent.WidthAndHeight;
window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
Binding asdf = new Binding("UnitsTotal");
asdf.Source = this[3][0].UnitsTotal;
asdf.Mode = BindingMode.OneWay;
block.SetBinding(TextBlock.TextProperty, asdf);
var asdfasdf = block.GetBindingBLOCKED EXPRESSION;
this code works using the same source and binding path. When side by side, the textblock will update, but the value presenter won't until it goes in and out of view.
I bound it instead to the Editor value property and it works correctly now. CellValuePresenter.Value must hard set it's value from some event with it's value editor, it was obviously detaching my binding when it did that.
cvp.Editor.SetBinding(ValueEditor.ValueProperty, binding);
I thought I tried this before, but I did so with a style setter and for some reason it didn't work. I'm sure that it was in my code where the problem was with that.