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.

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.

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

First create dictionary as I explained here.
In my case I've created TriggersDictionary.xaml, so my main window XAML looks like this:

<Window x:Class="PlayingWithResource.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    
        <Window.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary
                      Source= "TriggersDictionary.xaml">
                    </ResourceDictionary>
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
        </Window.Resources>
        <Grid>

        <Rectangle Style="{StaticResource styleWithTrigger}"></Rectangle>

    </Grid>
</Window>


My style (TriggersDictionary.xaml)

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Style x:Key="styleWithTrigger" TargetType="Rectangle">
        <Setter Property="Fill" Value="LightGreen" />
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Fill" Value="Red" />
            </Trigger>
        </Style.Triggers>
    </Style>

</ResourceDictionary>


Here you can see property - this is event which will be executed as well as target type (in my case rectangle)
Example project you can download from here, and this article I wrote using this page.

----

2014-06-16 Update Properties which are supported for trigger, for rectangle, for example you can see here.