|
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Windows;
using System;
namespace FsCalendarDemo
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
LoadCalendar();
}
/// <summary>
/// Loads highlighted dates from a text file into a FsCalendar control.
/// </summary>
private void LoadCalendar()
{
// Get folder containing this app
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var n = path.LastIndexOf(@"\bin");
var appFolderPath = path.Remove(n);
var fileName = String.Format(@"{0}\Holidays.txt", appFolderPath);
using (var reader = new StreamReader(fileName))
{
string line;
while ((line = reader.ReadLine()) != null)
{
// Parse line into data and tool tip
var s = line.Split(';');
var dateString = s[0];
var toolTip = s[1];
// Create DateTime object for date
var d = dateString.Split('/');
var date = new DateTime(DateTime.Now.Year, Convert.ToInt32(d[0]), Convert.ToInt32(d[1]));
// Add item to Calendar control's highlighted dates
DemoCalendar.HighlightedDates.Add(date, toolTip);
}
}
}
}
}
|
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.
David Veeneman is a financial planner and software developer. He is the author of "The Fortune in Your Future" (McGraw-Hill 1998). His company, Foresight Systems, develops planning and financial software.