Up vote 3 down vote favorite share g+ share fb share tw.
I'm trying to build up a page that will show a progress bar until the data is successfully downloaded from a server. For this I use a Generic data downloader that will simply populate the Model's properties and set the IsLoading property to true and/or false The View models look like: public class GenericPageModel: GenericModel { private bool _isLoading; public bool IsLoading { get { return _isLoading; } set { _isLoading = value; OnPropertyChanged("IsLoading"); } } } public class GenericModel : INotifyPropertyChanged { #region INotifyPropertyChanged Members public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged(string propName) { if (PropertyChanged! = null) { PropertyChanged(this, new PropertyChangedEventArgs(propName)); } } #endregion } The GenericPageModel is used in a XAML page as a Model and the IsLoading property is used as bellow: The generic data downloader: ... // Model that it's calling this public object Model { get; set; } private string _loadingProperty; ... void _bw_DoWork(object sender, DoWorkEventArgs e) { // Set the is loading property if (null!
= _loadingProperty) { //((Model as GenericModel). Owner as GenericPageModel). IsLoading = true; // Works!
Model.GetType(). GetProperty(_loadingProperty). SetValue(Model, true, null); // Doesn't work } } If I explicitly cast Model to the GenericPageModel and set the IsLoading to true, everything works just fine (see the commented line) If I use reflection to set the Value of the property, the IsLoading setter is hit correctly, the OnPropertyChanged method is called ok, but the UI doesn't update Is there something extra that needs to be done when setting a property trough reflection?
I 'm guessing the Events aren't raised properly but I can't figure out what to do. Solved there was an extra model inserted before the downloader call object Owner = Model.GetType(). GetProperty("Owner").
GetValue(Model, null); Model.GetType(). GetProperty(_loadingProperty). SetValue(Owner, true, null); c# wpf xaml data-binding reflection link|improve this question edited Dec 30 '11 at 13:16 asked Dec 30 '11 at 12:55Mori Andi183.
The following lines ((Model as GenericModel). Owner as GenericPageModel). IsLoading = true; // Works!
Model.GetType(). GetProperty(_loadingProperty). SetValue(Model, true, null); // Doesn't work are not equivalent.
The first affects the IsLoading property on the Model. Owner object, the second on the Model object itself. Note: your ViewModel base class really shouldn't be called GenericModel as it's the ViewModel, not the Model.
You're right, I was changing the property on the wrong object all along! Thanks, Happy New Year! – Mori Andi Dec 30 '11 at 13:13.
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.