Ali's profileAli DaneshmandiPhotosBlogListsMore ![]() | Help |
Ali DaneshmandiMicrosoft .Net Developer |
|||||
|
|
May 07 Restaurant WPF applicationMy first WPF application. I did it as a university assignment.
And here is the Demo Video
October 22 Persian support for silverlight 2.0The first important issue that every developer who desire to create an application on Microsoft Silverlight which uses the right to left languages such as Persian sould deal with, is to find a way to present RTL texts correctly on Silverlight content. The first time that I wanted to create a Persian Silverlight content I was really disappointed because Microsoft Silverlight does not support RTL languages well. So I decided to find a way to get rid of this problem. Now after spending hours and days the first result came into view; "Persian Support For Silverlight 2.0". This project provides a method to solve the RTL problem of silverlight for Persian texts. I upload it as an open source project on CodePlex website and you can download it from here. I 'll be glad to hear your ideas or comments.
Have a good time. September 02 Timers in WPFRecently I was working on a WPF app and I wanted to use a timer to do something automaticaly in the background and then update something in the UI. At first I was faced with some problems. But after all I found how I should use Timer in WPF So I decided to post it here for the ones who might face with the same issue.
First of all, here is the code which uses a timer to change the background color of the window with random generated color:
public partial class TimerTesting : Window
{ public TimerTesting() { InitializeComponent(); System.Threading.TimerCallback tc = new System.Threading.TimerCallback(this.OnTimerCallback); System.Threading.Timer objTimer = new System.Threading.Timer(tc); objTimer.Change(0, 500); } private void OnTimerCallback(Object obj) { Random r = new Random();
this } } When we wanted to set the background of the window in the Callback method this exception fires. "The calling thread cannot access this object because a different thread owns it.". This problem is due to UI thread in WPF is different from the thread that owns our timer. In fact, the Dispatcher object manage the UI (in this case the window). Therefore updating the UI should handle with Dispatcher object that owns it. So we should change our code in the CallBack method to this way:
private { this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (System.Threading.ThreadStart)delegate() { Random r = new Random(); this.Background = new SolidColorBrush(Color.FromRgb((byte)(r.Next(0, 255)), (byte)(r.Next(0, 255)), (byte)(r.Next(0, 255)))); }); } In WPF the only thread that created the DispatcherObject may access that object. Therefore we should first find the Dispatcher object of the window then tell it to update the data on the window. Moreover, The BeginInvoke method of the DispatcherObject executes the delegate asynchronously on the thread that the Dispatcher is associated with which in our code is the DispatcherObject of the window. In the Case of Timer, we can use three kinds of Timers in WPF which two of them were available before WPF; As we dicussed above System.Threading.Timer and System.Timers.Timer. But the third one is made especially for WPF; System.Windows.Threading.DispatcherTimer. The difference between this timer with the two others is that it belongs to the same thread as WPF UI thread. By that I mean the DispatcherObject owns it. Better say, in the case of our example above the thread of the window and the timer are the same so we can Update the UI data without any problem.
public {
public TimerTesting()
{
InitializeComponent();
System.Windows.Threading.DispatcherTimer dTimer = new System.Windows.Threading.DispatcherTimer();
dTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dTimer.Interval = TimeSpan.FromMilliseconds(500);
dTimer.Start();
}
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
Random r = new Random();
this.Background = new SolidColorBrush(Color.FromRgb((byte)(r.Next(0, 255)), (byte)(r.Next(0, 255)), (byte)(r.Next(0, 255))));
}
} You can download the complete source code here. Creating a CLR Persian Date Converter function for SQL ServerOne of the most exciting new features of MS SQL Server 2005 is its ability to host the .NET Common Language Runtime (CLR). This feature was not, however, designed merely to provide an alternative to Transact SQL (TSQL). In any development project, it is important to use the right tool for the right job. If you want to create a stored procedure that performs standard operations on relational data, then without doubt TSQL is the platform to choose. Since TSQL is designed solely for the purpose of manipulating relational data, it is superb at that job. However, there are many tasks which fall outside of the realm of relational data. It is for these tasks that CLR code might be a wise choice. Such tasks might include writing a Date convertor function to support Persian Date inside the Microsoft SQL Server. This is due to the lack of supporting Persian collation therefore SQL Server does not support Persian Date Time. However it seems that it should have, it is not yet affordable. We hope that Microsoft support it in the SQL Server 2008. Anyway, Thanks the .Net Framework 2.0 and later versions which has the PersianCalendar class in the System.Globalization namespace which enable us to use Persian calendar in the .Net environment. Now with the availability of embedding CLR functions into SQL Server we can write functions to convert the Georgian date time into Persian date time. In this article I will show how easy is to create Persian date time convertor in C# and then embedded it into SQL Server and finally use it as a function inside SQL Server environment. Because of the readability of the code I upload this article in Code Project. This the link: http://www.codeproject.com/KB/database/PersianDateInSQLServer.aspx |
Public folders
|
|||
|
|