last day (14 days later) » 

12:18 PM
1
A: Can't update UI from ViewModel in another classes

Fe DeTry the following: extend your ViewModel as follow: public class ViewModelClass : INotifyPropertyChanged { private CScheduler scheduler; //Add this: public static ViewModelClass Instance {get; set;} //NEW public ViewModelClass() { scheduler = new Scheduler(); } ...

 
Sounds good but there is a problem here: ViewModelClass.Instance = new ViewModelClass(); you use viewModel variable but isn't declared
 
use the ClassName instead as this is a static property it should work => ViewModelClass.Instance
 
ClassName? What do you mean?
 
@Dillinger is it working ?
 
I don't know if this working, I'm stuck to this: DataContext = viewModel.Instance; where should I get this variable?
 
12:18 PM
Dont use the variable use the Class itself same as when you use ViewModelClass variable = new ViewModelClass(); Use ViewModelClass.Insance in that case
@Dillinger did you copy the code from the DispatcherThread ?
im there .. D:
:D
 
Hi there, thanks for you time I've a slow connection today :(
 
no worries :D
 
anyway your code works but seems that I get the text duplicated in the control
 
so how can i help you
 
For example:
MainWindow.AppWindow.CScheduler.SyncLog.Dispatcher.Invoke(
() =>
{
if (ViewModelClass.Instance != null)
{
ViewModelClass.Instance.SynchronizationLog = Environment.NewLine + message + " [ORA: " + DateTime.Now + " ]";
ViewModelClass.Instance.SynchronizationLog = Environment.NewLine +
"------------------------------------------------------------------------------------";
}
});
in the control the text should be: ora.. blah blah and the ------------
but I get only the -----------
 
12:22 PM
that is absolutely right :D
ViewModelClass.Instance.SynchronizationLog = Environment.NewLine + message + " [ORA: " + DateTime.Now + " ]";
here you set the value for SynchronizationLog
and ViewModelClass.Instance.SynchronizationLog = Environment.NewLine +
"------------------------------------------------------------------------------------";
here you overwrite it :D
you have to append it :D
 
but in my viewModel I append the etxt
 
use += instead of =
 
text*
public string SynchronizationLog
{
get
{
return _text += _text;
}
set
{
_text = value;
OnPropertyChanged();//Il nome della proprietà viene passato automaticamente.
}
}
so I need to use += operator also when I set the text?
 
yeah not in return :D
you only return _text there :d
 
so should be:
MainWindow.AppWindow.CScheduler.SyncLog.Dispatcher.Invoke(
() =>
{
if (ViewModelClass.Instance != null)
{
ViewModelClass.Instance.SynchronizationLog += Environment.NewLine + message + " [ORA: " + DateTime.Now + " ]";
ViewModelClass.Instance.SynchronizationLog += Environment.NewLine +
"------------------------------------------------------------------------------------";
}
});
and
public string SynchronizationLog
{
get
{
return _text = _text;
}
set
{
_text = value;
OnPropertyChanged();//Il nome della proprietà viene passato automaticamente.
}
}
is this right?
 
12:24 PM
just get {return _text; }
get only gives you the value of the property
 
okay let me try
thanks :)
 
:D your welcome
 
ok seems working perfectly :)
could I ask just a thing?
 
sure just go ahead
 

last day (14 days later) »