- Details
- Written by: Stanko Milosev
- Category: WPF
- Hits: 4370
Update text box from another class For example, you need to update text box, but from another class. In that case, best would be if you provide class where is property which is bounded to the text box, something like:
public class SettingTheProperty { public SettingTheProperty(SetPropertyViewModel spvm) { spvm.DisplayText = "SettingTheProperty"; } }
Then call from main class would be like (in my case it is SetPropertyViewModel):
private void ShowMessage() { SettingTheProperty stp = new SettingTheProperty(this); }
Example project you can download from here.
- Details
- Written by: Stanko Milosev
- Category: WPF
- Hits: 3916
Today I was playing with threads.
I have no much to say about it, except the code.
Creating new thread is very simple:
Thread th = new Thread(MyThreadExample); th.Start();
Method MyThreadExample looks like this:
while (i < 10000000000000) { i++; Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Background, new Action( () => { DisplayCount = i.ToString(); OnPropertyChanged(() => this.DisplayCount); System.Threading.Thread.Sleep(10); })); }
Example you can download from here.
- Details
- Written by: Stanko Milosev
- Category: WPF
- Hits: 3838
If you want, for example, to show in a text box loop iterations in a real time, then you have to use something like:
Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Background, new Action( () => { DisplayCount = i.ToString(); OnPropertyChanged(() => this.DisplayCount); System.Threading.Thread.Sleep(10); }));
Where DiplayCount is property to which TextBox is binded. Here I explained how to use INotifyPropertyChanged, and from here you can download example.