c# - INotifyPropertyChanged.PropertyChanged fired, but UI not updated after form loads -
below illustration of model , viewmodel , xaml binding. viewmodel implements inotifypropertchanged. problem i'm having is...when wpf form first loads set activestock , see both setter , getter beingness called , ui updated reflect info correctly. however, when later set stockviewmodel.activestock, firepropertychanged invoked don't see getter beingness called, , consequently ui not update reflect new data. ideas might happening here?
the sec question have whether need raise propertychanged kid properties (pricedata , companydata) of model when viewmodel.activestock changed?
public class stock { public string ticker { get; set; } public stockdata pricedata { get; set; } public stockdata companydata { get; set; } } public class stockdata { ... } public class stockviewmodel:inotifypropertychanged { private stock _activestock; public stock activestock { get{ homecoming _activestock;} set{ _activestock = value; firepropertychanged("activestock");} } ... } xaml:
<usercontrol template="{staticresource stocktemplate}" datacontext="{binding activestock}" tag="{binding pricedata}" /> <usercontrol template="{staticresource stocktemplate}" datacontext="{binding activestock}" tag="{binding companydata}" /> edit: if remove datacontext binding usercontrol , instead set datacontext these 2 controls in code behind when activestock changes, works fine. why???
you might want seek specify mode property on datacontext bindings.
datacontext="{binding activestock, mode=oneway}" i'm not sure onetime default binding datacontext, explain if above helps.
the sec question has been answered sa_ddam213.
hth
c# wpf xaml
No comments:
Post a Comment