Databinding to a DependencyObject on a UserControl?

In your Exposed dependency property declaration, you have specified the name of the property incorrectly, "ExposedValue", rather than "Exposed".

Up vote 0 down vote favorite share g+ share fb share tw.

I have a UserControl, that is laid out like the following: A DeveloperExpress grid bound to an ObservableCollection called Data: public ObservableCollection Data { get; set; } A label with content bound to Cases, which is the first element of the Data collection: where: public SummaryData Cases { get; set; } private void LoadExampleDataIntoSummaryGrid() { Cases = new SummaryData() { Caption = "Cases", Exposed = "A", Unexposed = "B" }; Data. Add(Cases); Data. Add(new SummaryData() { Caption = "Controls", Exposed = "C", Unexposed = "D" }); } And, the code for SummaryData: public class SummaryData : DependencyObject { public string Caption { get; set; } public static readonly DependencyProperty ExposedProperty = DependencyProperty.

Register("ExposedValue", typeof(string), typeof(SummaryData), new UIPropertyMetadata(null)); public string Exposed { get { return (string)GetValue(ExposedProperty); } set { SetValue(ExposedProperty, value); } } public static readonly DependencyProperty UnexposedProperty = DependencyProperty. Register("UnexposedValue", typeof(string), typeof(SummaryData), new UIPropertyMetadata(null)); public string Unexposed { get { return (string)GetValue(UnexposedProperty); } set { SetValue(UnexposedProperty, value); } } public string Total { get { int exposed; int unexposed; if (Int32. TryParse(Exposed, out exposed) && Int32.

TryParse(Unexposed, out unexposed)) { return (exposed + unexposed).ToString(); } return String. Format("{0} + {1}", Exposed, Unexposed); } } } Note that "Exposed" and "Unexposed" are both DependencyProperties on a DependencyObject. My problem is that, when I use the Grid to update the Cases-object (and, I know it is indeed updated by using the debugger) the change is not reflected in the label.

I've checked, and the output window shows no databinding-errors. Furthermore, if I revert to having Exposed as a regular property, the initial value is read just fine (though updates aren't reflected, ofc. ) I've also tried inserting a Converter in the databinding (just a NOP converter that returns whatever it is given), and it is indeed never called... Any tips pit there?

:) wpf data-binding usercontrols dependency-properties link|improve this question asked Oct 19 '11 at 12:59Fafnr727 53% accept rate.

Anyway, I've tried changing it, but unfortunately it didn't help. – Fafnr Oct 20 '11 at 6:23 Do you have a complete example available for download that recreates the problem? Typically, for model types such as SummaryData, you would implement INotifyPropertyChanged, rather than using dependency properties, because that ties you into WPF and the model can't be reused on other platforms.

– devdigital Oct 20 '11 at 8:33 I just managed to get it working an hour or so ago - it was a COMPLETE brainfart, that I am embarassed that I posted here to begin with... I was creating the item I databind to after the InitializeComponent() call in my UserControl's constructor, which meant I was trying to databind to null, and of course when I then updated the values once the item was created, well, the databinding had already failed! Thanks so much for your help, though! – Fafnr Oct 20 '11 at 12:10 ha!

No problem :) – devdigital Oct 20 '11 at 13:02.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions