Custom items in WPF Calendar

Expanding on the previous post we will now modify the appearance of the calendar items through the use of a custom item presenter. To define the new presenter, simply create a new Style resource with TargetType set to ItemPresenter and place this Style somewhere in the resource look-up path – for example in the application’s or the window’s resource dictionaries. The Style must contain a setter for the Template property that defines the appearance of the item:

<style targettype="{x:Type planner:ItemPresenter}">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type planner:ItemPresenter}">
        <Grid>
        ...
        </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</style>

In this particular case the presenter represents a grid with two rows. The top row contains an icon and the header text of the item. The bottom row contains the description text. Note, that the TextBlock displaying the header text of the item has a name – HeaderBlock. The element with this name defines the position of the TextBox when the item is in-place edited.

Various appearance properties are also customized – such as FontFamily, Background and BorderBrush, by assigning new values to the respective properties of the Calendar.ItemSettings.CalendarStyle object:

calendar.ItemSettings.CalendarStyle.FontFamily = new FontFamily("Segoe UI");
calendar.ItemSettings.CalendarStyle.Background = Brushes.White;
calendar.ItemSettings.CalendarStyle.BorderBrush = Brushes.SlateGray;

Finally, the size of the calendar lanes is increased to accommodate the new appearance of the items:

calendar.ResourceViewSettings.LaneSize = 54;

The final result is displayed below.

scheduling-customitems

The complete sample project is available for download here:
https://mindfusion.eu/_samples/WpfPlannerCustomItems.zip

You can get the trial version of MindFusion.Scheduling for WPF from this link:
https://mindfusion.eu/WpfPlannerTrial.zip

Enjoy!

Implementing drag & drop in MindFusion.Scheduling for WPF

In this post we will discuss how to implement drag & drop using MindFusion.Scheduling for WPF. The goal is to enable users to create appointments by dragging items from an external source and dropping them onto the Calendar control surface.

The source

For the purposes of this sample the drag & drop source would be a simple ListBox control. The following XAML declares a ListBox with several predefined items:

  Task #1
  Task #2
  Task #3
  Task #4
  Task #5
  Task #6

The calendar

To enable the Calendar control to be the target of drag & drop operations, set its AllowDrop property to true. The following XAML snippet illustrates the definition of the Calendar control:

<planner:calendar x:name="calendar" grid.column="1" currentview="ResourceView" grouptype="GroupByResources" theme="Silver" allowdrop="True">
  <planner:calendar.itemresources>
    <planner:resource name="Resource #1">
    <planner:resource name="Resource #2">
    <planner:resource name="Resource #3">
  </planner:resource></planner:resource></planner:resource></planner:calendar.itemresources>
</planner:calendar>

The calendar is set up to display three resources in a Resource view.

The drag & drop

The drag & drop operation is initiated by calling the DragDrop.DoDragDrop static method and passing a reference to the dragged data. In our case we would want to initiate drag & drop when the user clicks on an item in the ListBox and starts dragging. Because the MouseDown event is consumed by the ListBox when the mouse is pressed over an item, we need to handle the PreviewMouseDown event. The following C# code displays the handlers of the PreviewMouseDown and MouseMove events:

private void taskList_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
  mouseDown = e.LeftButton == MouseButtonState.Pressed;
}

private void taskList_MouseMove(object sender, MouseEventArgs e)
{
  if (taskList.SelectedItem != null && mouseDown)
  {
    mouseDown = false;
    string data = ((ListBoxItem)taskList.SelectedItem).Content.ToString();
    DragDrop.DoDragDrop(taskList, data, DragDropEffects.Copy);
  }
}

To give visual feedback to the user when the mouse moves over the Calendar control during drag & drop operation, handle the DragOver event:

private void calendar_DragOver(object sender, DragEventArgs e)
{
  e.Effects = DragDropEffects.None;
  if (e.Data.GetDataPresent(typeof(string)))
  {
    DateTime? date = calendar.GetDateAt(e.GetPosition(calendar));
    if (date != null)
      e.Effects = DragDropEffects.Copy;
  }
}

This handler checks whether the dragged data matches the expected type and whether the location under the mouse cursor represents a valid date.

Finally, handle the Calendar.Drop event. This event is raised when the user releases the mouse over the Calendar control during a drag & drop operation.

private void calendar_Drop(object sender, DragEventArgs e)
{
  if (e.Data.GetDataPresent(typeof(string)))
  {
    Point point = e.GetPosition(calendar);
    DateTime? date = calendar.GetDateAt(point);
    Resource resource = calendar.GetResourceAt(point);
    if (date != null && resource != null)
    {
      string task = (string)e.Data.GetData(typeof(string));
      Appointment appointment = new Appointment();
      appointment.HeaderText = task;
      appointment.StartTime = date.Value;
      appointment.EndTime = appointment.StartTime.AddDays(2);
      appointment.Resources.Add(resource);
      calendar.Schedule.Items.Add(appointment);
    }
  }
}

The following image shows the running sample with several created appointments:

Drag & drop

The source code is available for download from here:

Download the Complete Source Code for the Sample

You can get the trial version of MindFusion.Scheduling for WPF from this link:

Download MindFusion.Scheduling for WPF Trial Version

MindFusion.Pack for WPF 2013.R1

We have just has released MindFusion.Pack for WPF 2013.R1. There are new features in most of the components in the pack. Here are the details:

Support for VisualStudio 2012

The pack installer creates VS2012 toolbox palette for all the components and can optionally install VS2012 sample projects. Toolbox palettes are also created for all .NET target environments supported by the respective Visual Studio versions.

chartMindFusion.Charting

Style and Themes

Styles define the appearance of a given chart element – the axis, the series, the legend. Each ChartTheme is a collection of styles. You can:

• create themes based on the appearance of an existing chart
• create themes with the ThemeEditor tool
• save themes to XML files
• load themes from XML files
• use a number of predefined themes

The green theme

The green theme

Improved Design Time Support

You can now edit all collection properties, including the Series collection, the brushes, strokes, legends and all other collections in design time through the property grid.

Axis Intervals

The new AxisSettings.IntervalCount property lets you specify the exact number of intervals at the axis. In such case the control does not use the Interval property and calculates the value of each interval based on AxisSettings.Min, AxisSettings.Max and AxisSettings.IntervalCount.

A bar chart with two Y-axes.

A bar chart with two Y-axes.

API Changes

diagram16x16MindFusion.Diagramming

Preserve order in tree layout

You can set now the Balance property of the TreeLayout to Preserve if you want to keep the original geometric order of child nodes when arranging them under their parent. This can be used to arrange tree branches in a specific order by first positioning them in increasing horizontal or vertical positions.

The tree layout.

The tree layout.

Selection improvements

  • Set Behavior to SelectOnly to let users select existing items, but not modify them or draw new ones.
  • Use the SetsDirtyFlag property of the Selection class to specify whether the Dirty flag should be set when selection changes.
  • The SelectionStartMoving event is now raised when the user begins moving multiple selected items.
  • Use the ToggleSelection modifier key to select or deselect items by clicking. The key disables selection via lasso rectangle.

Miscellaneous

Container nodes

Container nodes

Report-16x16MindFusion.Reporting

Exporting

You can now use the new PdfExporter and MhtmlExporter, which enable exporting to the PDF and MHTML formats respectively. You can find detailed information about the new exporters in the “Exporting Reports” theme.

Side-By-Side Containers

You can arrange items parallelly by putting them inside the new SideBySideContainer report item. You can use it, for example, to display two (or more) data ranges one next to the other.

A classic report.

A classic report.

Miscellaneous

• New DefaultEncoding property in PdfExporter;
• New Median aggregate function;

Calendar-16x16MindFusion.Scheduling

Improved item presenter

The ItemPresenter class gives you the start and end time of the represented item fragment through the new
StartTime and EndTime properties. In addition, derived classes can override the new OnStartTimeChanged,
OnEndTimeChanged, and OnItemPropertyChanged methods to get notified when the StartTime or EndTime properties change or when any property of the underlying item changes.

Item recurrence

Item recurrence

Improved recurrence

You can validate and customize the occurrences of a recurrence pattern with the new ValidateOccurrence event of the Recurrence class.

You can find more about the new features of the components at the forum. Here is a link to download the trial version:

Download MindFusion.Pack for WPF 2013.R1

About MindFusion.Wpf Pack: A set of advanced WPF components that help you build your business application easy and on time. The tools provide you with a complete set of features to create, edit and render complex flowcharts, charts, diagrams, calendars, schedules, maps and reports. A set of gauges and UI elements is also included. Each component offers various samples, tutorials and detailed documentation. The controls offer simple and intuitive API, completely customizable appearance, numerous input/output options and a rich event set. Each tool has been thoroughly tested to guarantee that you and your application get the high quality and performance you deserve.

You can read more about the capabilities of each component at its features page:

Prices and licenses are explained in details at the buy page. We offer permanent discounts to certain types of commercial as well non commercial organizations – check here if you qualify.

Scheduling for ASP.NET 3.1

We have released version 3.1 of MindFusion.Scheduling for ASP.NET. The new features include:

  • items can be resized interactively in all views
  • Visual Studio 2012 support
  • some CSS classes have been renamed to provide better consistency across themes. Check the updated CSS Classes help topic for details.
  • the bundled jQuery version has been upgraded to 1.9

webplanner

Registered customers with an active upgrade subscription can download the licensed version from the clients area on our site.

A trial version is available for download from this link:

Download MindFusion.Scheduling for ASP.NET 3.1

Technical support

MindFusion takes pride in providing excellent customer support to all its clients and evaluators. You can contact us per e-mail support@mindfusion.eu, at the forum or the help desk. We’ll be happy to assist you.

About MindFusion.Scheduling for ASP.NET: A programming tool suitable for creating any type of calendar, schedule, time table, resource table and more. The control supports 5 data views that are easy to change; rich event set and user interaction model. Users can create items interactively, define recurring events, or define custom-typed events, scroll the view or use drag&drop to modify an item.

The control provides programmatic access to all schedule objects. The appearance is completely customizable, built-in themes are also available. At run-time, appointments are created and edited with the built-in form. Every feature is documented in details, there are many tutorials and samples, which provide plenty of code to copy and study. You can learn more about Scheduling for ASP.NET here.

MindFusion.WinForms Pack, R1.2013

The new features include preserve order in the tree layout for the diagramming tool, new events in the calendar control, layout improvements in reporting for WinForms and more. Here are the details:

diagram16x16MindFusion.Diagramming

Preserve order in tree layout

You can set the Balance property of the TreeLayout to Preserve to keep the original geometric order of child nodes when arranging them under their parent. This can be used to arrange tree branches in a specific order by first positioning them in increasing horizontal or vertical positions.

Tree Layout

Tree Layout

Item rendering improvements

Table nodes with glass, emboss and shadow effects.

Table nodes with glass, emboss and shadow effects.

Export improvements

Selection improvements

Report-16x16MindFusion.Reporting

We have fixed several bugs and made a few layout improvements in the reporting component.

Calendar-16x16MindFusion.Scheduling

New Events

Two new events were added to the Calendar class – BeginItemDrawing and EndItemDrawing raised when item drawing starts and ends respectively.

Exporting

You can use the new PdfExporter to export calendars to PDF files.

A schedule exported as a PDF file.

A schedule exported as a PDF file.

You can read more details about the new features of each component at the forum. Use the link below to download the trial version of the control:

Download MindFusion.WinForms Pack R1.2013

If you run into problems with any of the components, please let us know. We shall be glad to assist you. MindFusion is proud with its excellent technical support – the majority of the questions are answered within hours of receiving them.

About MindFusion.WinForms Pack: A set of five WinForms programming components that provide your application with a rich choice of diagramming, charting, scheduling, mapping, reporting and gauge features. The tools are very easy to implement and use. They boast intuitive API and various step-by-step tutorials to get you started. Both online and offline documentation is available. A sample browser presents you with all the samples for each control to let you easily navigate to what you need. You can check some of the features of each component right now if you look at the online demos:

Visit the features – page of the components for more information about their capabilities:

You can check the prices and licensing scheme here. All components are royalty-free.