Silverlight / WPF - Date comparison in WPF datepicker and how to change the Date Format

Asked By Farhan
20-Jun-10 07:08 AM

Hi,

 

1) How can I compare my Startdate and EndDate.I want  StartDate<=EndDate. This I want to knwo both through XAML and through code also.

 

2) I want to change date format of datepicker from dd/mm/yyyy to mm/dd/yyyy.

 

Can anyone help me.

 

Look up the TimeSpan class and IValueConverter for XAML  Look up the TimeSpan class and IValueConverter for XAML

20-Jun-10 07:15 AM

IValueConverters are the primary way data is validated in XAML when bound to class properties.  You can do this in the XAML or you can dynamically adjust the binding at runtime.  Here's an article on doing it at runtime:

 

http://www.eggheadcafe.com/tutorials/aspnet/fb496607-14b3-4f0a-af9c-71731557c486/wpf--silverlight-dynamically-change-data-binding-attributes-at-runtime.aspx

  Eriawan Kusumawardhono replied to Farhan
07-Jul-10 08:30 AM

Hi,

To compare a date you can simply call Compare method on the DateTime class.

Example: (taken from MSDN)

DateTime date1 = new DateTime(2009, 8, 1, 0, 0, 0);

DateTime date2 = new DateTime(2009, 8, 1, 12, 0, 0);

int result = DateTime.Compare(date1, date2);

string relationship;


if (result < 0) relationship = "is earlier than";

else if (result == 0) relationship = "is the same time as";

else relationship = "is later than";

Console.WriteLine("{0} {1} {2}", date1, relationship, date2);

// The example displays the following output:

// 8/1/2009 12:00:00 AM is earlier than 8/1/2009 12:00:00 PM



Changing DatePicker format depends on the current system Culture and UI Culture.

Create New Account
help
Silverlight 2 Beta 2 - Doing Data Part IV: Browser / Cookie Interaction As you travel in your Silverlight oddysey, you will discover that there is often a need for persisting simple state and interacting with the underlying browser DOM. Fortunately, Silverlight's System.Windows.Browser namespace makes this easy. We create a Silverlight Twitter Search widget using the Twitter API. We'll save searches in a cookie, navigate that our kind friends at Twitter are enabling cross-domain access for us. When the Silverlight Page class initializes, I check for a cookie called "search". If it isn't null use the System.Windows.Browser.HtmlPage.Window.Navigate method to make the browser - not the Silverlight app - request the selected page. Having saved the search in a cookie, when the user clicks their browser's Back button, our Silverlight app reads the cookie, and re-issues the request, redisplaying the results of the last Uri(itm.Id.ToString())); } private void SetCookie( string key, string value ) { / / Expire in 7 days DateTime expireDate = DateTime.Now + TimeSpan.FromDays(7); string newCookie = key + " = " + value + ";expires = " + expireDate.ToString( "R" ); HtmlPage
using timer to update the silver light page Silverlight / WPF hi all, i have a silver light page in my asp.net project im using silverlight 3 . . . . . . i want to implement a timer control in my silverlight app. . . so that it should update the page by getting data from sql in a minute timne gap. . . i dont have nay idea for implementing the timer controls in silverlight please advice me. . . thanks in advance muthu Hi, You can use the DispatcherTimer , private void args) { counterPanel.Children.Clear(); counterPanel.Children.Add( new TextBlock { Text = counter++.ToString() }); }; timer.Interval = new TimeSpan(0, 0, 1); / / one second timer.Start(); } Here is an example here which although titled Silverlight 2 will work just the same in SL3: http: / / pagebrooks.com / archive / 2008 / 03 / 07 silverlight-2-has-a-timer-dispatchertimer.aspx Non non-UI use you also have the Timer phase = = 0) { / / On the first click, create the timer. outputBlock.Text + = " \ nCreating the timer at " + DateTime.Now.ToString( "h:mm:ss.fff" ) + ", to start in 1 second with a half-second
Silverlight IsolatedStorage Compressed Object Cache One of the most useful features of Silverlight 3 is the IsolatedStorage mechanism, which gives the developer access to the filesystem on the client to store data. Now that Silverlight has matured sufficiently to be used in line – of – business and Enterprise – level applications, having there's code to do both, so you decide. In either case, I use a Silverlight port of MiniLzo by Markus Oberhumer that was put together by Owen Emlen in C for the sake of completeness. Here is an example of how you would use the Silverlight IsolatedStorage Compressed Object Cache to Store, and then to reload a Collection: private void butGenerate_Click( object sender, RoutedEventArgs e) { NotesList list = new NotesList(); Silverlight.Utils.CacheUtility<NotesList> util = null ; for ( int i = 0;i<5000;i++) { Note note = new Note(DateTime.Now.ToString(), "Subject Line " +i.ToString( ), "This is note " +i.ToString( ), 1, "" ); list.Notes.Add handler, I make a call to increase the IsolatedStorage quota. The user will get a Silverlight prompt the first time, and they can OK it. The IncreaseQuota method is in the
Painting the Canvas with Silverlight 2.0 Now that Silverlight 2.0 BETA 1 is out, developers are discovering some unique and compelling applications. Here is a short example of how to paint a Silverlight Canvas with randomly colored and sized rectangles. There is a lot of developer interest in Silverlight 2.0. If you go to my ittyurl.net "social tagging short urls" site and search on the silverlight tag you will see that a number of very smart people have been using the facility to draw attention to their Silverlight work (you are welcome to use the site, too). I too have started to take an interest in Silverlight, and though the applications I am currently working on do not really apply, I expect do. So, I want to devote a small portion of my available "study time" to Silverlight as it evolves. One thing I like to do with a new programming medium is
Silverlight 2 Beta 2 - Doing Data Part V: Realtime StockQuotes / Scrolling Display With Silverlight, most of the "data" you will use you'll get via some sort of networking under the hood. Here we scrape realtime stock quotes and display them in a scrolling Silverlight "Marquee" display. Silverlight makes all network - related calls using the Asynchronous method pattern. You cannot make a synchronous http request with Silverlight managed code. Recently there was a heated thread (the "bring back sync calls petition") on the Silverlight Forums with lots of people happy to chime in and sign up, but only a understanding why "it is what it is", and why it needs to be that way. Silverlight wants - - and needs - - to be "very" cross-browser. In order to accomplish this, it must it was a real shocker to those who had gotten so used to previous beta Silverlight versions that didn't have the urgency to be true "browser plugins". Now that's