Micro blog about Answer to the Ultimate Question of Life, the Universe, and Everything.
  • Home
    • List all categories
    • Sitemap
  • Downloads
    • WebSphere
    • Hitachi902
    • Hospital
    • Kryptonite
    • OCR
    • APK
  • About me
    • Gallery
      • Italy2022
      • Côte d'Azur 2024
    • Curriculum vitae
      • Resume
      • Lebenslauf
    • Social networks
      • Facebook
      • Twitter
      • LinkedIn
      • Xing
      • GitHub
      • Google Maps
      • Sports tracker
    • Adventures planning
  1. You are here:  
  2. Home
  3. C#

Update text box from another class

Details
Written by: Stanko Milosev
Category: WPF
Published: 06 May 2014
Last Updated: 30 November -0001
Hits: 4937

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.

Simple thread

Details
Written by: Stanko Milosev
Category: WPF
Published: 04 May 2014
Last Updated: 04 May 2014
Hits: 4468

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.

Display realtime log

Details
Written by: Stanko Milosev
Category: WPF
Published: 01 May 2014
Last Updated: 05 April 2022
Hits: 4452

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.

Open XAML without designer

Details
Written by: Stanko Milosev
Category: WPF
Published: 09 April 2014
Last Updated: 09 April 2014
Hits: 5275

Right click on the XAML file, and click "Open With..":

 

Choose Source Code (Text) Editor, and click "Set as Default":

Next time when you double click on XAML file, it will be opened without design, and faster.

 

Thanks to colleagues from ISE

  1. Playing with triggers
  2. Dispatcher processing has been suspended, but messages are still being processed.
  3. Update binding
  4. More about binding

Subcategories

WPF

Beginning

Code snippets

NUnit

LINQ

Windows Forms

Page 26 of 38

  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30