RadGanttView For Silverlight and WPF

Similar documents
RadPDFViewer For Silverlight and WPF

Introduction to Data Templates and Value Converters in Silverlight

Hands-On Lab. Sensors -.NET. Lab version: Last updated: 12/3/2010

Week 8: Data Binding Exercise (Bookstore)

Authoring Guide Gridpro AB Rev: Published: March 2014

WPF and MVVM Study Guides

Week 7: NavigationView Control Exercise

Authoring Guide v2.1 PATRIK SUNDQVIST

Developing Native Windows Phone 7 Applications for SharePoint

Note: This demo app created for this lab uses the Visual Studio 2015 RTM and Windows Tools SDK ver

WebFront for Service Manager

CPSC Tutorial 5

CPSC Tutorial 5 WPF Applications

sharpcorner.com/uploadfile/37db1d/4958/default.aspx?articleid=cb0b291c-52ae-4b80-a95c- 438d76fa1145

04 Sharing Code Between Windows 8 and Windows Phone 8 in Visual Studio. Ben Riga

Sparkline for WPF 1. ComponentOne. Sparkline for WPF

Name of Experiment: Student Database


Accurate study guides, High passing rate! IT TEST BOOK QUESTION & ANSWER. Ittestbook provides update free of charge in one year!

Portable Class Libraries ---

About 1. Chapter 1: Getting started with xaml 2. Remarks 2. Versions 2. Examples 2. Hello World 2. Installation or Setup 3

This tutorial is designed for software developers who want to learn how to develop quality applications with clean structure of code.

Note: many examples in this section taken or adapted from Pro WPF 4.5 C#, Matthew MacDonald, apress, 2012, pp

About 1. Chapter 1: Getting started with xaml 2. Remarks 2. Versions 2. Examples 2. Installation or Setup 2. Hello World 2

This document contains a general description of the MVVMStarter project, and specific guidelines for how to add a new domain class to the project.

SAMPLE CHAPTER. C# and XAML. Pete Brown MANNING

Workspace Desktop Edition Developer's Guide. Customize Views and Regions

Mobile Computing. Xamarin Data Binding MVVM Pattern. Data Binding. XAML binding example. Target Views. In simple apps. For complex or big apps

Mobile Computing Xamarin Data Binding MVVM Pattern

Cross Platform Development Windows 8 Windows Phone 8

Course 2D_SL: 2D-Computer Graphics with Silverlight Chapter C5: The Complete Code of PathAnimation. Copyright by V. Miszalok, last update:

var xdoc = XDocument.Load(inStream);

Name of Experiment: Country Database

Hands-On Lab. Building Applications in Silverlight 4 Module 6: Printing the Schedule. Printing the Schedule

Integration with AppBar

Extending ArcGIS Pro with.net and Python: Interactive Analytics. Carlos A. Osorio-Murillo Mark Janikas

Hands-On Lab. Hello Windows Phone

Advanced Programming C# Lecture 3. dr inż. Małgorzata Janik

Hands-On Lab. Using Bing Maps

windows-10-universal #windows- 10-universal

CS3240 Human-Computer Interaction Lab Sheet Lab Session 2

Launchers and Choosers Hands-on Lab. Hands-On Lab. Launchers and Choosers. Lab version: Last updated: 12/8/2010. Page 1

03 Model-View-ViewModel. Ben Riga

ComponentOne. Extended Library for UWP

New Insights into Process Deviations Using Multivariate. Control Charts

NE.15 Data Binding In Windows Presentation Foundation

Hands-On Lab. Using Pivot and Panorama Controls

Master Code on Innovation and Inclusion

Lecture # 6 Engr. Ali Javed 11th March, 2014

ArcGIS Pro SDK for.net: Advanced User Interfaces in Add-ins. Wolfgang Kaiser

INFRAGISTICS Silverlight 15.1 Volume Release Notes 2015

LAYOUT. Chapter 3 of Pro WPF : By Matthew MacDonald Assist Lect. Wadhah R. Baiee. College of IT Univ. of Babylon

Lab 7: Silverlight API

Studio Productivity Tools Q2 2013

ComponentOne. Imaging for UWP

For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to

The Model provides underlying data, sometimes involving file or web accesses.

Microsoft Windows Apps Dev w/microsoft.net Framework 4. Download Full Version :

ArcGIS Pro SDK for.net Beginning Pro Customization. Charles Macleod

ArcGIS Pro SDK for.net: UI Design and MVVM

Chromatic Remote Control Product Guide Executive Way, Suite A Frederick, MD 21704

Windows Presentation Foundation Programming Using C#

Lesson 9: Exercise: Tip Calculator

Styles and Control Templates

Hands-On Lab. Building Applications in Silverlight 4 Module 7: Event Administrator Dashboard with Out of Browser, Toasts and Native Integration

1.1 Why Foxit MobilePDF SDK is your choice Foxit MobilePDF SDK Key Features of Foxit PDF SDK for UWP Evaluation...

Chapter 16 Data binding

ComponentOne. PdfViewer for Silverlight

ComponentOne. GanttView for WPF

Telerik Corp. Test Studio Standalone & Visual Studio Plug-In Quick-Start Guide

ReportPlus Embedded Desktop SDK Guide

AddFlow for Silverlight V 2.0 Tutorial

Migrating to Windows Phone

SCICHART v2.0 (BETA 2)

Mastering LOB Development

Getting Started with ExcelMVC

ArcGIS Pro SDK for.net Advanced User Interfaces in Add-ins. Wolfgang Kaiser

This book was purchased by

Step4: Now, Drag and drop the Textbox, Button and Text block from the Toolbox.

INFRAGISTICS WPF 16.1 Service Release Notes December 2016

NetAdvantage for WPF 13.1 Service Release Notes August 2013

Universal Windows Platform Complete Solution

WRITING THE MANAGEMENT SYSTEM APPLICATION

Road Map for Essential Studio 2010 Volume 1

For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to

Annex B: Prototype Draft Model Code. April 30 th, 2015 Siamak Khaledi, Ankit Shah, Matthew Shoaf

INFRAGISTICS Silverlight 15.2 Volume Release Notes 2015

Windows Phone 8 Game Development

ESSENTIAL STUDIO 2014 V O L U M E 2

10Tec igrid for.net 6.0 What's New in the Release

ArcGIS Pro SDK for.net UI Design for Accessibility. Charles Macleod

CS3240 Human-Computer Interaction Lab Sheet Lab Session 4 Media, Ink, & Deep Zoom

Windows Presentation Foundation (WPF)

ArcGIS API for Silverlight An Introduction

Creating a Spreadsheet by Using Excel

ArcGIS Pro Extensibility - Building and Deploying Addins with the new DotNet SDK

Interface Builders and Interface Description Languages

Media Programming on mobile devices (Windows Phone)

DOT.NET MODULE 6: SILVERLIGHT

ComponentOne. Xamarin Edition

Transcription:

RadGanttView For Silverlight and WPF This tutorial will introduce RadGanttView, part of the Telerik suite of XAML controls. Setting Up The Project To begin, open Visual Studio and click on the Telerik menu option. Under Rad Controls For Silverlight click on Create New Telerik Project. Name your project, accept Silverlight 5 and in the Project Configuration Wizard dialog check GanttView. When you click ok, the necessary assembly is added to the References as shown in figure 1 Figure 1 Your application will open to MainPage.xaml and, thanks to the Telerik Visual Studio extensions, the namespace telerik will already have been created in the XAML heading.

<UserControl x:class="radbarcode.gettingstarted.mainpage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" mc:ignorable="d" d:designwidth="640" d:designheight="480"> Add a RadGanttView to the Layout grid in the XAML file, <telerik:radganttview Name="xGanttView"> </telerik:radganttview> Open the code-behind file, where we will do three things, 1. Define tasks to add to the GanttView 2. Set the Pixel Length to determine how wide the display of each day will be 3. Set the Visible Range We set the visible range by providing an instance of VisibleRange passing in a starting date and an ending date, var d = new DateTime(2012, 3, 1); xganttview.visiblerange = new VisibleRange(d, d.addmonths(2)); We set the PixelLength by passing in a TimeSpan, as shown in figure 2, Figure 2 Finally, we need to add tasks (and sub-tasks) to the GanttView. We start by creating an observable collection of GanttTask objects, var tasks = new ObservableCollection<GanttTask>(); Next, we ll create four parent tasks, each with a start, end and title, for (int i = 0; i<4; i++) var gt = new GanttTask( d.adddays(14 * i), d.adddays(14 * i + 14), "Title " + i.tostring()); For each task we ll create a set of child tasks based on the task s duration in days,

for (int j = 0; j < gt.duration.days; j++) var childgt = new GanttTask(); childgt.start = gt.start.adddays(j); childgt.end = childgt.start.addhours(23); childgt.title = "Child " + i.tostring() + "/" + j.tostring(); Add each child to the children collection of the GanttTask gt.children.add(childgt); Add the GanttTask to the ObservableCollection tasks.add(gt); Finally, add the ObservableCollection as the TasksSource for the GanttView, xganttview.taskssource = tasks; When you run the application you ll see the tasks and subtasks, but because we set the PixelLength to 1 day, you can t see much detail. Change the PixelLength to 1 hour, xganttview.pixellength = new TimeSpan(0, 1, 0, 0); Run the application again and you should get a better view of the Gantt chart, complete with parent and child tasks and durations, as shown in figure 3,

Figure 3 Relations Let s establish a relationship among the various child tasks. Relationships add a link between tasks. To do so, first set the PixelLength to 15 minutes. Then add the following code immediately after the creation of ChildGt, if ( j > 0 ) GanttTask prevgt = gt.children[j - 1] as GanttTask; prevgt.setrelations(new List<Relation>() new Relation() Task = childgt ); The result is that you can now get a better view of the relationships among the child tasks, as shown in figure 4,

Figure 4 GanttViewHighlighting To examine GanttViewHighlighting in depth, we ll start a new project, very similar to the previous except this time we ll also add Telerik.Windows.Controls.Input to the references. Add two rows and two columns to the Layoutroot as shown here, <Grid.RowDefinitions> <RowDefinition /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition /> </Grid.ColumnDefinitions> <telerik:radganttview Name="xRadGanttView" Grid.ColumnSpan="2" /> Let s start by creating the ViewModel class. Name it GanttVM and be sure to set it to derive from ViewModelBase (a base for ViewModel classes provided by the Telerik library). public class GanttVM : ViewModelBase Declare an observable collection of GanttTask objects,

public ObservableCollection<GanttTask> Tasks get; set; and initialize it in your constructor. public GanttVM() Tasks = new ObservableCollection<GanttTask>(); LoadTasks(); The LoadTasks method will be based on the code used in the previous example, private void LoadTasks() var d = new DateTime(2012, 3, 1); for (int i = 0; i < 4; i++) var gt = new GanttTask(d.AddDays(14 * i), d.adddays(14 * i + 14), "Title " + i.tostring()); for (int j = 0; j < gt.duration.days; j++) var childgt = new GanttTask(); childgt.start = gt.start.adddays(j); childgt.end = childgt.start.addhours(23); childgt.title = "Child " + i.tostring() + "/" + j.tostring(); if (j > 0) GanttTask prevgt = gt.children[j - 1] as GanttTask; prevgt.setrelations(new List<Relation>() new Relation() Task = childgt ); gt.children.add(childgt); Tasks.Add(gt); Declare a property of type VisibleRange, public VisibleRange GanttRange get; set; And initialize that property in the constructor, GanttRange = new VisibleRange(new DateTime(2012, 3, 1), new DateTime(2012, 5, 1));

In this case we ve initialized it to start on March 1, 2012 and to span two months. Build the application just to make sure there are no errors or typos. Return to the Xaml file and add a local namespace, xmlns:local="clr-namespace:ganttchartmvvm" You ll use this to create a resource to hold the VM, <UserControl.Resources> <local:ganttvm x:key="xvm" /> </UserControl.Resources> This lets us set the DataContext in the LayoutRoot, <Grid x:name="layoutroot" DataContext="StaticResource xvm"> We re now ready to update the bindings on the RadGanttView, <telerik:radganttview Name="xGanttView" Grid.ColumnSpan="2" TasksSource="Binding Tasks" VisibleRange="Binding GanttRange"/> You should now see the GanttChart in the designer. If not, try rebuilding the application. Let s add a slider control to our application, <telerik:radslider x:name="xradslider" Grid.Row="1" Minimum="10000000" Maximum="30000000000" Value="18000000000" Margin="5,10" /> The extremely large values are because we ll be converting these values to ticks for a timespan. Create a new class TicksToTimespanConverter and add the following code, public class TicksToTimeSpanConverter : IValueConverter public object Convert(object value, Type targettype, object parameter, CultureInfo culture) return TimeSpan.FromTicks((long)(double)value); public object ConvertBack(object value, Type targettype, object parameter, CultureInfo culture)

throw new NotImplementedException(); Build the application. Add the converter to the resources in MainPage.xaml, <UserControl.Resources> <local:ganttvm x:key="xvm" /> <local:tickstotimespanconverter x:key="xconverter" /> </UserControl.Resources> We can now add the binding for the PixelLength to the RadGanttView in the XAML, <telerik:radganttview Name="xGanttView" Grid.ColumnSpan="2" TasksSource="Binding Tasks" VisibleRange="Binding GanttRange" PixelLength=" Binding ElementName=xRadSlider, Path=Value, Converter=StaticResource xconverter"/> Run the application. We now have a slider at the bottom which works to zoom in and out on our Gantt chart, as shown in figure 5

Figure 5 We re now going to add a toggle button which will turn highlighting on and off. We re using the RadTogglebutton and Radslider which are part of the suite of Telerik tools for Silverlight and WPF <telerik:radtogglebutton Name="xRadToggleButton" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Content="Highlight" /> We need a public property to bind the IsChecked attribute to. Open the ViewModel and add the following property, private bool checkedvalue; public bool CheckedValue get return checkedvalue; set if ( checkedvalue!= value) checkedvalue = value; OnPropertyChanged(() => this.checkedvalue);

You can now update the ToggleButton s IsChecked property, <telerik:radtogglebutton Name="xRadToggleButton" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Content="Highlight" IsChecked="Binding CheckedValue, Mode=TwoWay"/ The toggle button doesn t yet affect the highlighting. First thing we need is another collection, just of the highlighted tasks, public ObservableCollection<GanttTask> HighlightedTasks get; set; Initialize that collection in the constructor, HighlightedTasks = new ObservableCollection<GanttTask>(); We need a method to make the highlighting happen, private void ToggleHighlight(bool? amihighlighted) if (amihighlighted == null) return; If the argument is null, we just return. Otherwise, we clear the collection and if the argument is true, for this demo, we ll randomly add tasks and children to the list of highlighted tasks, HighlightedTasks.Clear(); if (amihighlighted == true) var rnd = new Random(); GanttTask parentgt = Tasks[rnd.Next(0, Tasks.Count)] as GanttTask; int randnumber = rnd.next(2, parentgt.children.count - 2); for (int i = 2; i < randnumber; i++) HighlightedTasks.Add(parentGT.Children[i] as GanttTask); Returning to the property CheckedValue, after we set the value we ll call ToggleHighlight,

ToggleHighlight(CheckedValue); Now that we have a collection of the tasks we want to highlight, return to the XAML and in the definition for the GanttView we add one more attribute, <telerik:radganttview Name="xGanttView" Grid.ColumnSpan="2" TasksSource="Binding Tasks" VisibleRange="Binding GanttRange" PixelLength="Binding ElementName=xRadSlider, Path=Value, Converter=StaticResource xconverter" HighlightedItemsSource="Binding HighlightedTasks"/> Run the application, click the Highlight button and scroll down until you find the highlighted task and children, as shown in figure 6, Figure 6 Clicking the toggle button a second time will make the highlighting disappear. Custom GanttTask Let s create a custom GanttTask so that we can add criteria to that task that does not exist in the default.

We ll create a new class called TeamGanttTask. The new class will inherit from the default GanttTask, public class TeamGanttTask : GanttTask We ll create the two constructors that our base class needs, public TeamGanttTask() : base() public TeamGanttTask(DateTime startdate, DateTime enddate, string title) : base(startdate, enddate, title) Add a new property to the custom TeamGanttTask, private int teamid; public int TeamID get return teamid; set if (teamid!= value) teamid = value; OnPropertyChanged(() => this.teamid); We ll use this new property to create custom business logic to control highlighting. Add two new observable collections to the VM, public ObservableCollection<TeamGanttTask> TeamTasks get; set; public ObservableCollection<TeamGanttTask> HighlightedTeamTasks get; set; Don t forget to modify the initialization in the constructor, TeamTasks = new ObservableCollection<TeamGanttTask>(); HighlightedTeamTasks = new ObservableCollection<TeamGanttTask>(); We ll also modify LoadTasks to LoadTeamTasks, //LoadTasks(); LoadTeamTasks(); Copy and paste LoadTasks to the new method, LoadTeamTasks and make the appropriate substitutions (e.g., TeamGanttTask for GanttTask).

Next, set the new property on the ChildGanttTask, childgt.teamid, Random rnd = new Random(); private void LoadTeamTasks() var d = new DateTime(2012, 3, 1); for (int i = 0; i < 4; i++) var gt = new TeamGanttTask(d.AddDays(14 * i), d.adddays(14 * i + 14), "Title " + i.tostring()); for (int j = 0; j < gt.duration.days; j++) var childgt = new TeamGanttTask(); childgt.start = gt.start.adddays(j); childgt.end = childgt.start.addhours(23); childgt.title = "Child " + i.tostring() + "/" + j.tostring(); childgt.teamid = rnd.next(0, 4); if (j > 0) TeamGanttTask prevgt = gt.children[j - 1] as TeamGanttTask; prevgt.setrelations(new List<Relation>() new Relation() Task = childgt ); gt.children.add(childgt); TeamTasks.Add(gt); Don t forget to update the binding in MainPage.xaml, <telerik:radganttview Name="xGanttView" Grid.ColumnSpan="2" TasksSource="Binding TeamTasks" VisibleRange="Binding GanttRange" PixelLength="Binding ElementName=xRadSlider, Path=Value, Converter=StaticResource xconverter" HighlightedItemsSource="Binding HighlightedTeamTasks"/> Before we proceed we need a new property to hold the selectedtask, private TeamGanttTask selectedtask; public TeamGanttTask SelectedTask get return selectedtask; set if ( selectedtask!= value) selectedtask = value;

OnPropertyChanged(() => this.selectedtask); Returning to MainPage.xaml we ll use that new property for a new binding, <telerik:radganttview Name="xGanttView" Grid.ColumnSpan="2" TasksSource="Binding TeamTasks" VisibleRange="Binding GanttRange" PixelLength="Binding ElementName=xRadSlider, Path=Value, Converter=StaticResource xconverter" HighlightedItemsSource="Binding HighlightedTeamTasks" SelectedItem="Binding SelectedTask, Mode= TwoWay "/> Finally, we just need to update our highlighting logic to work with our new TeamTasks. Copy and paste ToggleHighlight to ToggleTeamHighlight. void ToggleTeamHighlight(bool? amihightlighting) if (amihightlighting == null SelectedTask == null) return; HighlightedTeamTasks.Clear(); if (amihightlighting == true) int counter = TeamTasks.Count; for (int i = 0; i < counter; i++) We iterate through the tasks and find the children where the teamid matches the selected team id, TeamGanttTask tgt = TeamTasks[i]; var teamkids = tgt.children.oftype<teamgantttask>(). Where(x => x.teamid == SelectedTask.TeamId); foreach (var teamkid in teamkids) HighlightedTeamTasks.Add(teamkid); Run the application and select a child. Toggle the Highlight button and all the children on the same team are highlighted as well.