- databinding.zip
- AppReferences
- IronPython.dll
- Microsoft.Scripting.Core.dll
- Microsoft.Scripting.dll
- Microsoft.Scripting.ExtensionAttribute.dll
- DataBinding.sln
- DataBindingSilverlightUI.Web
- DataBindingSilverlightUI
- DataBindingUI
- ViewModelLibrary
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Input;
using System.Xml.Linq;
#if (SILVERLIGHT)
using DataBindingSilverlightUI;
#endif
namespace ViewModelLibrary.CalendarViewModel
{
public sealed class Calendar : INotifyPropertyChanged
{
public Calendar()
{
this.PropertyChanged += new PropertyChangedEventHandler(OnCalendarPropertyChanged);
this.CurrentMonth = new DateTime(2009, 10, 13);
this.nextMonthCommand = new DelegateCommand<Calendar>(
this,
c => c.CurrentMonth.AddMonths(1).Year < 2010,
delegate(Calendar c) { c.CurrentMonth = c.CurrentMonth.AddMonths(1); });
this.prevMonthCommand = new DelegateCommand<Calendar>(
this,
c => c.CurrentMonth.AddMonths(-1).Year >= 2009,
delegate(Calendar c) { c.CurrentMonth = c.CurrentMonth.AddMonths(-1); });
}
private void OnCalendarPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "CurrentMonth")
{
RefreshWeekList();
RefreshFlickrPhotoList();
}
}
private void RefreshFlickrPhotoList()
{
this.FlickrUriList = null;
var request = WebRequest.Create(string.Format("http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=<Add_your_api_key_here>&min_taken_date={0}&max_taken_date={1}",
this.CurrentMonth.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture),
this.CurrentMonth.AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)));
request.BeginGetResponse(delegate(IAsyncResult asyncResult)
{
using (var response = request.EndGetResponse(asyncResult))
{
using (var stream = response.GetResponseStream())
{
using (var reader = new StreamReader(stream))
{
var flickrResult = XDocument.Load(reader);
this.flickrUriList =
(from r in flickrResult.Descendants("photo")
select new Uri(string.Format(CultureInfo.InvariantCulture,
"http://farm{0}.static.flickr.com/{1}/{2}_{3}.jpg",
r.Attribute("farm").Value,
r.Attribute("server").Value,
r.Attribute("id").Value,
r.Attribute("secret").Value), UriKind.Absolute)).ToList();
#if ( SILVERLIGHT )
App.MainPageDispatcher.BeginInvoke(
new Action(() => this.OnPropertyChanged("FlickrUriList")), null);
#else
Application.Current.Dispatcher.BeginInvoke(
new Action(() => this.OnPropertyChanged("FlickrUriList")), null);
#endif
}
}
}
}, null);
}
private void RefreshWeekList()
{
var result = new List<Week>();
DateTime currentDate;
currentDate = (currentDate = this.CurrentMonth.AddDays((-1) * (this.CurrentMonth.Day - 1)) - this.CurrentMonth.TimeOfDay).AddDays(
(((int)currentDate.DayOfWeek) + 6) % 7 * (-1));
while (currentDate.Month == this.CurrentMonth.Month ||
currentDate.AddDays(6).Month == this.CurrentMonth.Month)
{
result.Add(new Week(currentDate, this.CurrentMonth.Year, this.CurrentMonth.Month));
currentDate = currentDate.AddDays(7);
}
this.Weeks = result;
}
private DateTime currentMonth;
public DateTime CurrentMonth
{
get { return this.currentMonth; }
set
{
if (this.currentMonth != value)
{
this.currentMonth = value;
this.OnPropertyChanged("CurrentMonth");
}
}
}
private IList<Week> weeks;
public IList<Week> Weeks
{
get { return this.weeks; }
private set
{
this.weeks = value;
this.OnPropertyChanged("Weeks");
}
}
private ICommand nextMonthCommand;
public ICommand NextMonthCommand
{
get
{
return this.nextMonthCommand;
}
}
private ICommand prevMonthCommand;
public ICommand PrevMonthCommand
{
get
{
return this.prevMonthCommand;
}
}
private IList<Uri> flickrUriList;
public IList<Uri> FlickrUriList
{
get { return this.flickrUriList; }
set
{
this.flickrUriList = value;
this.OnPropertyChanged("FlickrUriList");
}
}
#region INotifyPropertyChanged
private void OnPropertyChanged(string propName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
}
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Hi, my name is Rainer Stropek. I am living a small city named Traun in Austria. Since 1993 I have worked as a developer and IT consultant focusing on building database oriented solutions. After being a freelancer for more than six years I founded a small IT consulting company together with some partners in 1999. In 2007 my friend Karin and I decided that we wanted to build a business based on COTS (component off-the-shelf) software. As a result we founded "software architects" and developed the time tracking software "time cockpit" (
http://www.timecockpit.com). If you want to know more about our companies check out my blogs at
http://www.software-architects.com and
http://www.timecockpit.com or take a look at my profile in XING (
http://www.openbc.com/hp/Rainer_Stropek2/).
I graduated the Higher Technical School for MIS at Leonding (A) in 1993. After that I started to study MIS at the Johannes Kepler University Linz (A). Unfortunately I had to stop my study because at that time it was incompatible with my work. In 2005 I finally finished my BSc (Hons) in Computing at the University of Derby (UK). Currently I focus on IT consulting, development, training and giving speeches in the area of .NET and WPF, SQL Server and Data Warehousing.