Click here to Skip to main content
13,146,739 members (80,833 online)

Silverlight / WPF

 
AnswerRe: Root element is not valid for navigation Pin
Richard Deeming21-Jan-13 1:55
memberRichard Deeming21-Jan-13 1:55 
GeneralRe: Root element is not valid for navigation Pin
Vuyiswa Maseko21-Jan-13 4:49
memberVuyiswa Maseko21-Jan-13 4:49 
QuestionRandom Image with array Pin
Tikha17-Jan-13 11:23
memberTikha17-Jan-13 11:23 
AnswerRe: Random Image with array Pin
Pete O'Hanlon17-Jan-13 21:21
protectorPete O'Hanlon17-Jan-13 21:21 
AnswerRe: Random Image with array Pin
Abhinav S19-Jan-13 2:24
mvpAbhinav S19-Jan-13 2:24 
GeneralRe: Random Image with array Pin
Tikha21-Jan-13 17:09
memberTikha21-Jan-13 17:09 
GeneralRe: Random Image with array Pin
Dave Kreskowiak21-Jan-13 17:54
mvpDave Kreskowiak21-Jan-13 17:54 
QuestionDispatcherTimer Tick event not fired Pin
Praveen Raghuvanshi17-Jan-13 4:54
memberPraveen Raghuvanshi17-Jan-13 4:54 
Hi,

I am working on a WPF application. The application uses Infragistics controls such as Ribbon Controls and XamDockManager. It has a File Menu wherein I have provided a Save menu item to save the items on the canvas to a file. On click of Save button, Save Dialog opens to provide the File name and file is saved at the defined location.
The saving process is quite time consuming and in order to show something to the user, I have used the WaitCursor.
I have used a class similar to the one mentioned(UiServices.ShowWaitCursor) in the below thread.

http://stackoverflow.com/questions/7346663/how-to-show-a-waitcursor-when-the-wpf-application-is-busy-databinding[^]

http://stackoverflow.com/questions/3480966/display-hourglass-when-application-is-busy[^]

The usage is like this

public void WriteToFile(string fileName)
{
UiServices.SetBusyState();
_customFileWriter.WriteToFile(fileName);
}

This works fine, if we just save the things on the canvas into a file. However, if fails in the below scenario.
The application has a canvas where I display some UI elements. On double click of the UI element, we launch a Windows form in the Infragistic ContentPane.
We have a modeless dialog opened and perform File -> Save and provide a file name, the cursor stays indefinitely. It goes only once we click on the Canvas. The DispatcherTimer_Tick is fired only when we click on the Canvas which resets the cursor.

The DispatcherPriority is ApplicationIdle.
Another observation is, this happens only when we open the Save dialog through the File -> Save. It works fine if we open the Save dialog through Ctrl + S key combinations.

Is there a way I can debug the non firing of DispatcherTimer.Tick event or any other way to handle this?

I created a simple WPF application and it works fine in that.

MainWindow.xaml

<Window x:Class="WpfApplication1.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">
 
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Menu Height="36" Name="menu1" Margin="12,0,439,197">
            <MenuItem Header="_File" Height="22" Name="menuitem1" Width="200" Margin="10, 10, 5, 5" HorizontalAlignment="Left" VerticalAlignment="Top" Background="Chocolate">
                <MenuItem Header="Save..."  Click="MenuItem_Click"/>
            </MenuItem>
        </Menu>
        <Canvas Height="156" HorizontalAlignment="Left" Margin="81,77,0,0" Name="canvas1" VerticalAlignment="Top" Width="304" Background="#FF945050">
            <Button Canvas.Left="128" Canvas.Top="49" Content="Button" Height="23" Name="button1" Width="75" Click="button1_Click" />
            <TextBox Canvas.Left="48" Canvas.Top="128" Height="23" Name="textBox1" Width="120" />
        </Canvas>
    </Grid>
</Window>


MainWindow.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
 
namespace WpfApplication1
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
	{
		public MainWindow()
		{
			InitializeComponent();
		}
 
		private void button1_Click(object sender, RoutedEventArgs e)
		{
			System.Windows.Forms.Form form = new System.Windows.Forms.Form();
			form.Height = 200;
			form.Width = 400;
			form.TopMost = true;
			form.Show();
		}
 
		private void MenuItem_Click(object sender, RoutedEventArgs e)
		{
			string fileName = SaveFileDialog();
			UiServices.SetBusyState();
			System.Threading.Thread.Sleep(3000);
		}
 
		private string SaveFileDialog()
		{
			// Create SaveFileDialog
			Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
 
			// Display SaveFileDialog by calling ShowDialog method
			Nullable<bool> result = dlg.ShowDialog();
 
			string filename = string.Empty;
			// Get the selected file name 
			if (result == true)
			{
				// Open document
				filename = dlg.FileName;
			}
			return filename;
		}
	}
 
	/// <summary>
	/// Sets the busy state on the application.
	/// Displays a wait cursor for long running tasks.
	/// </summary>
	public static class UiServices
	{
		/// <summary>
		/// A value indicating whether the UI is currently busy
		/// </summary>
		private static bool _isBusy;
 
		/// <summary>
		/// Sets the state as busy.
		/// </summary>
		public static void SetBusyState()
		{
			SetBusyState(true);
		}
 
		/// <summary>
		/// Sets the state to busy or not busy.
		/// </summary>
		/// <param name="busy">if set to <c>true</c> the application is now busy.</param>
		private static void SetBusyState(bool busy)
		{
			if (busy != _isBusy &&
				Application.Current != null &&
				Application.Current.Dispatcher != null)
			{
				_isBusy = busy;
				Mouse.OverrideCursor = busy ? Cursors.Wait : null;
 
				if (_isBusy)
				{
					new DispatcherTimer(TimeSpan.FromSeconds(0), DispatcherPriority.ApplicationIdle, DispatcherTimer_Tick, Application.Current.Dispatcher);
				}
			}
		}
 
		/// <summary>
		/// Handles the Tick event of the dispatcherTimer control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
		private static void DispatcherTimer_Tick(object sender, EventArgs e)
		{
			var dispatcherTimer = sender as DispatcherTimer;
			if (dispatcherTimer != null)
			{
				SetBusy(false);
				dispatcherTimer.Stop();
			}
		}		
	}
}


Thanks in advance!
AnswerRe: DispatcherTimer Tick event not fired Pin
Paulo Zemek23-Jan-13 6:28
memberPaulo Zemek23-Jan-13 6:28 
QuestionWhich way to load entity child collections? Pin
UCLAdam16-Jan-13 5:11
memberUCLAdam16-Jan-13 5:11 
QuestionWPF with Web Pin
Rishabh Kumar14-Jan-13 8:42
memberRishabh Kumar14-Jan-13 8:42 
AnswerRe: WPF with Web Pin
Abhishek Pant14-Jan-13 9:17
memberAbhishek Pant14-Jan-13 9:17 
AnswerRe: WPF with Web Pin
Abhinav S16-Jan-13 17:20
mvpAbhinav S16-Jan-13 17:20 
QuestionWPF - Bind IsEnabled To Method On VM Pin
Kevin Marois13-Jan-13 11:06
memberKevin Marois13-Jan-13 11:06 
AnswerRe: WPF - Bind IsEnabled To Method On VM Pin
Wayne Gaylard14-Jan-13 0:55
mentorWayne Gaylard14-Jan-13 0:55 
AnswerRe: WPF - Bind IsEnabled To Method On VM Pin
Richard Deeming14-Jan-13 2:13
memberRichard Deeming14-Jan-13 2:13 
GeneralRe: WPF - Bind IsEnabled To Method On VM Pin
Kevin Marois14-Jan-13 10:40
memberKevin Marois14-Jan-13 10:40 
GeneralRe: WPF - Bind IsEnabled To Method On VM Pin
Kevin Marois20-Jan-13 8:47
memberKevin Marois20-Jan-13 8:47 
QuestionWPF - Sync Combox Pin
Kevin Marois12-Jan-13 15:19
memberKevin Marois12-Jan-13 15:19 
AnswerRe: WPF - Sync Combox Pin
Mycroft Holmes13-Jan-13 0:50
memberMycroft Holmes13-Jan-13 0:50 
GeneralRe: WPF - Sync Combox Pin
Kevin Marois13-Jan-13 17:24
memberKevin Marois13-Jan-13 17:24 
GeneralRe: WPF - Sync Combox Pin
Mycroft Holmes14-Jan-13 0:11
memberMycroft Holmes14-Jan-13 0:11 
GeneralRe: WPF - Sync Combox Pin
Kevin Marois14-Jan-13 5:25
memberKevin Marois14-Jan-13 5:25 
GeneralRe: WPF - Sync Combox Pin
SledgeHammer0114-Jan-13 9:34
memberSledgeHammer0114-Jan-13 9:34 
GeneralRe: WPF - Sync Combox Pin
Kevin Marois23-Jan-13 17:41
memberKevin Marois23-Jan-13 17:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy |
Web01 | 2.8.170915.1 | Last Updated 22 Sep 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid