Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is ugly but it works. By delaying the initiliazation of the long running operation using a DispatcherTimer we can allow the UI to be updated before the operation is started. </p> <p>XAML:</p> <pre><code>&lt;UserControl x:Class="SilverlightApplication13.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"&gt; &lt;Grid x:Name="LayoutRoot" Background="White"&gt; &lt;StackPanel&gt; &lt;Border x:Name="Brd01" Visibility="Collapsed" Background="Red"&gt; &lt;TextBlock VerticalAlignment="Center" Margin="30"&gt;Sleeping for 4 seconds...&lt;/TextBlock&gt; &lt;/Border&gt; &lt;Border x:Name="Brd02" Visibility="Collapsed" Background="Lime"&gt; &lt;TextBlock VerticalAlignment="Center" Margin="30"&gt;Done!&lt;/TextBlock&gt; &lt;/Border&gt; &lt;Button Content="Start Operation" Click="Button_Click_1"&gt;&lt;/Button&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre> <p>Code-behind:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Threading; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.Windows.Threading; namespace SilverlightApplication13 { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); } private void Button_Click_1(object sender, RoutedEventArgs e) { //Show the "working..." message Brd01.Visibility = System.Windows.Visibility.Visible; //Initialize a timer with a delay of 0.1 seconds var timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromMilliseconds(100); timer.Tick += Timer_Tick; timer.Start(); } private void Timer_Tick(object sender, EventArgs e) { //Start the long running operation Thread.Sleep(4000); Brd01.Visibility = System.Windows.Visibility.Collapsed; Brd02.Visibility = System.Windows.Visibility.Visible; //Kill the timer so it will only run once. (sender as DispatcherTimer).Stop(); (sender as DispatcherTimer).Tick -= Timer_Tick; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload