<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>ILOG .NET Visualization Blog &#187; WPF</title>
	<link>http://blogs.ilog.com/netvisu</link>
	<description>Postings from the Visualization .NET Development Team</description>
	<pubDate>Fri, 28 Nov 2008 13:39:40 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.2</generator>
	<language>en</language>
			<item>
		<title>Selected User Meeting Presentations: A (French) Film Festival</title>
		<link>http://blogs.ilog.com/netvisu/2008/08/25/selected-user-meeting-presentations-a-french-film-festival/</link>
		<comments>http://blogs.ilog.com/netvisu/2008/08/25/selected-user-meeting-presentations-a-french-film-festival/#comments</comments>
		<pubDate>Mon, 25 Aug 2008 08:19:51 +0000</pubDate>
		<dc:creator>Emmanuel Tissandier</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[Ajax]]></category>

		<category><![CDATA[Diagram]]></category>

		<category><![CDATA[Visual Studio]]></category>

		<category><![CDATA[WPF]]></category>

		<category><![CDATA[Adobe]]></category>

		<category><![CDATA[Diagrammer for .NET]]></category>

		<category><![CDATA[Microsoft]]></category>

		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://blogs.ilog.com/netvisu/2008/08/25/selected-user-meeting-presentations-a-french-film-festival/</guid>
		<description><![CDATA[Ed Kiraly has posted in the JViews blog a <a href="http://blogs.ilog.com/jviews/2008/08/22/selected-user-meeting-presentations-a-french-film-festival/">series of videos </a>recorded during a user group meeting in Paris. The recorded sessions (in French) are from our CEO, from the Visualization product team and from Microsoft and Adobe. You will find here a&#8230;]]></description>
			<content:encoded><![CDATA[<p>Ed Kiraly has posted in the JViews blog a <a href="http://blogs.ilog.com/jviews/2008/08/22/selected-user-meeting-presentations-a-french-film-festival/">series of videos </a>recorded during a user group meeting in Paris. The recorded sessions (in French) are from our CEO, from the Visualization product team and from Microsoft and Adobe. You will find here a video showing how a easily create a graph display using WPF and Diagrammer for .NET.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ilog.com/netvisu/2008/08/25/selected-user-meeting-presentations-a-french-film-festival/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Creating a Nice Diagram Display with WPF :  It&#8217;s So Easy</title>
		<link>http://blogs.ilog.com/netvisu/2008/06/18/creating-a-nice-diagram-display-with-wpf-its-so-easy/</link>
		<comments>http://blogs.ilog.com/netvisu/2008/06/18/creating-a-nice-diagram-display-with-wpf-its-so-easy/#comments</comments>
		<pubDate>Wed, 18 Jun 2008 20:26:23 +0000</pubDate>
		<dc:creator>Ed Kiraly</dc:creator>
		
		<category><![CDATA[Diagram]]></category>

		<category><![CDATA[Visual Studio]]></category>

		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://blogs.ilog.com/netvisu/2008/06/18/creating-a-nice-diagram-display-with-wpf-its-so-easy/</guid>
		<description><![CDATA[In this short 7 minute presentation, Patrick Megard leads us through the basic steps in creating a diagram display using ILOG Diagrammer for .NET's and Visual Studio 2008's WPF features.

<em>The following movie is best viewed in full screen mode:</em>
<p align="center">&#160;</p>
<em>Presented&#8230;</em>]]></description>
			<content:encoded><![CDATA[<p>In this short 7 minute presentation, Patrick Megard leads us through the basic steps in creating a diagram display using ILOG Diagrammer for .NET&#8217;s and Visual Studio 2008&#8217;s WPF features.</p>
<p><em>The following movie is best viewed in full screen mode:</em></p>
<p align="center">&nbsp;</p>
<p><embed enablejs="true" overstretch="true" allowfullscreen="true" allowscriptaccess="always" flashvars="file=http://visudemos.ilog.com/videos/WPFandD4NET.flv&amp;displayheight=360" height="360" width="522" src="http://visudemos.ilog.com/videos/mediaplayer.swf" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed><em>Presented by Patrick Megard.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ilog.com/netvisu/2008/06/18/creating-a-nice-diagram-display-with-wpf-its-so-easy/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Displaying a Microsoft Project XML file using Diagrammer for .NET, WPF and LinQ (Part 2)</title>
		<link>http://blogs.ilog.com/netvisu/2008/05/29/displaying-a-microsoft-project-xml-file-using-diagrammer-for-net-wpf-and-linq-part-2/</link>
		<comments>http://blogs.ilog.com/netvisu/2008/05/29/displaying-a-microsoft-project-xml-file-using-diagrammer-for-net-wpf-and-linq-part-2/#comments</comments>
		<pubDate>Thu, 29 May 2008 13:55:57 +0000</pubDate>
		<dc:creator>Emmanuel Tissandier</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[Diagram]]></category>

		<category><![CDATA[Linq]]></category>

		<category><![CDATA[WPF]]></category>

		<category><![CDATA[Diagrammer for .NET]]></category>

		<guid isPermaLink="false">http://blogs.ilog.com/netvisu/2008/05/29/displaying-a-microsoft-project-xml-file-using-diagrammer-for-net-wpf-and-linq-part-2/</guid>
		<description><![CDATA[In the <a href="http://blogs.ilog.com/netvisu/2008/05/19/displaying-a-microsoft-project-xml-file-using-diagrammer-for-net-wpf-and-linq-part-1/">part 1</a> of this post, we have seen how to use <a href="http://www.ilog.com/products/diagrammernet">ILOG Diagrammer for .NET</a>, WPF and Linq to display the content of a Microsoft Project XML file into a graph showing the tasks and the constraints between them,&#8230;]]></description>
			<content:encoded><![CDATA[<p>In the <a href="http://blogs.ilog.com/netvisu/2008/05/19/displaying-a-microsoft-project-xml-file-using-diagrammer-for-net-wpf-and-linq-part-1/">part 1</a> of this post, we have seen how to use <a href="http://www.ilog.com/products/diagrammernet">ILOG Diagrammer for .NET</a>, WPF and Linq to display the content of a Microsoft Project XML file into a graph showing the tasks and the constraints between them, we are now going to see how to use more WPF features to display the critical path of the project.<br />
The critical path of the project is simply the set of tasks that are critical. The task is considered as critical if a delay in the task will delay the end of the project. This set of tasks and the constraints between them usually creates a path in the network, called the critical path although sometime you might see several paths.<br />
For our example, we will fist try to display the critical tasks with a red background and give some information on different type of tasks.</p>
<p>We add 3 new boolean properties to our Task class, a Milestone property for tasks that are milestones, a Summary property for tasks that represents a group of tasks, and a Critical property for critical tasks.</p>
<pre>
 public bool Milestone { get; set; }
 public bool Summary { get; set; }
 public bool Critical { get; set; }</pre>
<p>and we change the Linq query to fill these properties from the XML file:</p>
<pre>
project.Tasks
      = (from task in document.Descendants("{http://schemas.microsoft.com/project}Task")
          where (int)task.Element("{http://schemas.microsoft.com/project}ID") != 0
          select new Task()
           {
               Project = project,
               UID = (int)task.Element("{http://schemas.microsoft.com/project}UID"),
               Name = (string)task.Element("{http://schemas.microsoft.com/project}Name"),
               Start = (DateTime)task.Element("{http://schemas.microsoft.com/project}Start"),
               Finish = (DateTime)task.Element("{http://schemas.microsoft.com/project}Finish"),
               <strong>Milestone = (bool)task.Element(&#8221;{http://schemas.microsoft.com/project}Milestone&#8221;),
               Critical = (bool)task.Element(&#8221;{http://schemas.microsoft.com/project}Critical&#8221;),
               Summary = (bool)task.Element(&#8221;{http://schemas.microsoft.com/project}Summary&#8221;),</strong>
               PredecessorLinks =
                         (from link in task.Descendants(&#8221;{http://schemas.microsoft.com/project}PredecessorLink&#8221;)
                         select
                           new PredecessorLink
                           {
                               PredecessorUID = (int)link.Element(&#8221;{http://schemas.microsoft.com/project}PredecessorUID&#8221;)
                           }).ToList()  

              }).ToList();</pre>
<p>Now that our Task has 3 new properties we can modify the style of nodes with data triggers to take advantage of this. The data trigger in a style will allow changing the style depending on data. In our case, milestones will be white, summary tasks in blue and all critical tasks in red.<br />
Here is the new style for nodes with 3 data triggers.</p>
<pre>
 &lt;Style TargetType="{x:Type ilog:Node}" &gt;
     &lt;Setter Property="Background" Value="#FFF0A5"/&gt;
     &lt;Setter Property="BorderBrush" Value="#468966"/&gt;
     &lt;Setter Property="BorderThickness" Value="1"/&gt;  

     <strong>&lt;Style.Triggers&gt;  

        &lt;DataTrigger Binding=&#8221;{Binding Summary}&#8221; Value=&#8221;true&#8221;&gt;
           &lt;Setter Property=&#8221;Background&#8221; Value=&#8221;blue&#8221;/&gt;
        &lt;/DataTrigger&gt;  

        &lt;DataTrigger Binding=&#8221;{Binding Milestone}&#8221; Value=&#8221;true&#8221;&gt;
           &lt;Setter Property=&#8221;Background&#8221; Value=&#8221;white&#8221;/&gt;
           &lt;Setter Property=&#8221;CornerRadius&#8221; Value=&#8221;10&#8243;/&gt;
        &lt;/DataTrigger&gt;  

        &lt;DataTrigger Binding=&#8221;{Binding Critical}&#8221; Value=&#8221;true&#8221;&gt;
           &lt;Setter Property=&#8221;Background&#8221; Value=&#8221;red&#8221;/&gt;
        &lt;/DataTrigger&gt;  

      &lt;/Style.Triggers&gt;</strong>
 &lt;/Style&gt;</pre>
<p>The definition of data triggers is very straight forward. The data trigger evaluates the value specified by the Binding (for example {Binding Summary}) and see if it matches the value specified in the Value property (in our case true), if the two things match, then the setters are applied, in our case the background color is changed.</p>
<p>Two things to understand here, first the binding specified in the data trigger is evaluated on the data context of the Node. In the <strong>Diagram</strong> control the data context for node is the item in the data source, in our case a Task object, that is why I can directly bind to the properties of a Task (like {Binding Milestone}), no need to specify any source for the binding.<br />
The second point is the order of the triggers. I place the last trigger that changes the background to red for critical tasks at the end because a milestone or a summary task can also be critical. The last data trigger will win in such a case and thus all critical tasks will be red.<br />
We now have the following result, showing the critical tasks :</p>
<p><a href="http://blogs.ilog.com/netvisu/wp-content/uploads/2008/05/diagram3.png" title="diagram3.png"><img src="http://blogs.ilog.com/netvisu/wp-content/uploads/2008/05/diagram3.png" alt="Critical Path" /></a></p>
<p>We can also use data triggers in data templates. For example, for a milestone task it is not necessary to display the start and finish date since the dates are the same.<br />
In order to achieve this we add a data trigger in the data template of nodes:</p>
<pre>
&lt;DataTemplate x:Key="TaskTemplate"&gt;
  &lt;Grid  Margin="5" MaxWidth="150" x:Name="grid"&gt;
    &lt;Grid.RowDefinitions&gt;
      &lt;RowDefinition/&gt;
      &lt;RowDefinition/&gt;
      &lt;RowDefinition/&gt;
    &lt;/Grid.RowDefinitions&gt;
    &lt;TextBlock
       x:Name="header" Grid.Row ="0"
       Text="{Binding Path=Name}"
       TextWrapping="WrapWithOverflow"
       Foreground="#FFB03B"
       FontWeight="Bold"/&gt;
    &lt;StackPanel x:Name="startField"  Grid.Row ="1" Orientation="Horizontal"&gt;
      &lt;TextBlock x:Name="startLabel" Text="Start:"/&gt;
      &lt;TextBlock Text="{Binding Path=Start}"/&gt;
    &lt;/StackPanel&gt;
    &lt;StackPanel x:Name="finishField" Grid.Row ="2" Orientation="Horizontal"&gt;
      &lt;TextBlock x:Name="finishLabel" Text="Finish:"/&gt;
      &lt;TextBlock Text="{Binding Path=Finish}"/&gt;
    &lt;/StackPanel&gt;
  &lt;/Grid&gt;
  <strong>&lt;DataTemplate.Triggers&gt;
    &lt;DataTrigger Binding=&#8221;{Binding Milestone}&#8221; Value=&#8221;true&#8221;&gt;
        &lt;Setter TargetName=&#8221;startLabel&#8221; Property=&#8221;Text&#8221; Value=&#8221;Milestone Date:&#8221;/&gt;
        &lt;Setter TargetName=&#8221;finishField&#8221; Property=&#8221;Visibility&#8221; Value=&#8221;Collapsed&#8221;/&gt;
    &lt;/DataTrigger&gt;
  &lt;/DataTemplate.Triggers&gt; </strong>
&lt;/DataTemplate&gt;</pre>
<p>The trigger here applies to task with Milestone property set to true, it changes the label of the start date to &#8220;Milestone Date&#8221; and hides the part that corresponds to the end date.</p>
<p>Here is the result for a one of the milestones:</p>
<p><a href="http://blogs.ilog.com/netvisu/wp-content/uploads/2008/05/diagram4.png" title="diagram4.png"><img src="http://blogs.ilog.com/netvisu/wp-content/uploads/2008/05/diagram4.png" alt="Templated Milestone" /></a></p>
<p>Let&#8217;s now use data triggers for links. In order to make the critical path more obvious, we will try to draw the links between two critical tasks in red. Painting a critical task in red was easy; we have simply added a data trigger in the style. For links it is a little bit more complex because there is no instance in the data source that represents a link. To answer this problem, The Wpf diagram component creates a convenient data context for each link that is an instance of the class <strong>Diagram.LinkContext</strong>. This class has two properties, <strong>StartItem</strong> and <strong>EndItem</strong> that represents the items in the data source (for us the tasks) that are at the displayed at the begining and end of the link. Thus we can easily use data triggers in a link of the diagram.<br />
We want the link to be red if both the origin and destination tasks are critical, so we need to use a <strong>MultiDataTrigger</strong> that is a kind of data trigger with multiple conditions:</p>
<p>Here is the new style for links:</p>
<pre>
&lt;Style TargetType="{x:Type ilog:Link}" &gt;
  &lt;Setter Property="Radius" Value="10"/&gt;
  &lt;Setter Property="Stroke" Value="#FFF0A5"/&gt;
  &lt;Setter Property="StrokeThickness" Value="2"/&gt;
  &lt;Setter Property="StartArrow"&gt;
    &lt;Setter.Value&gt;
      &lt;ilog:LinkArrow  Fill="White"  Shape="Circle"/&gt;
    &lt;/Setter.Value&gt;
  &lt;/Setter&gt;
  &lt;Setter Property="EndArrow"&gt;
    &lt;Setter.Value&gt;
      &lt;ilog:LinkArrow Fill="{x:Null}"  Shape="Open"/&gt;
    &lt;/Setter.Value&gt;
  &lt;/Setter&gt;
  <strong>&lt;Style.Triggers&gt;
    &lt;MultiDataTrigger&gt;
      &lt;MultiDataTrigger.Conditions&gt;
        &lt;Condition Binding=&#8221;{Binding StartItem.Critical}&#8221; Value=&#8221;true&#8221;/&gt;
        &lt;Condition Binding=&#8221;{Binding EndItem.Critical}&#8221; Value=&#8221;true&#8221;/&gt;
      &lt;/MultiDataTrigger.Conditions&gt;
      &lt;Setter Property=&#8221;Stroke&#8221;  Value=&#8221;red&#8221;/&gt;
      &lt;Setter Property=&#8221;StrokeThickness&#8221;  Value=&#8221;3&#8243;/&gt;
    &lt;/MultiDataTrigger&gt;</strong>
  &lt;/Style.Triggers&gt;
&lt;/Style&gt;</pre>
<p>I hope I have shown how the combination of the diagram control with its graph layout algorithms and the styling and templating features of WPF can help to easily create nice looking diagrams.</p>
<p>If you want to test the project, <a href="http://blogs.ilog.com/netvisu/wp-content/uploads/2008/05/criticalpath.zip" title="Project files">here is the source code</a> and Visual Studio 2008 solution. In order to compile and run you will need and evaluation of ILOG Diagrammer for .NET that you can get at <a href="http://www.ilog.com/products/diagrammernet/eval">http://www.ilog.com/products/diagrammernet/eval</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ilog.com/netvisu/2008/05/29/displaying-a-microsoft-project-xml-file-using-diagrammer-for-net-wpf-and-linq-part-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Displaying a Microsoft Project XML file using Diagrammer for .NET, WPF and LinQ (Part 1)</title>
		<link>http://blogs.ilog.com/netvisu/2008/05/19/displaying-a-microsoft-project-xml-file-using-diagrammer-for-net-wpf-and-linq-part-1/</link>
		<comments>http://blogs.ilog.com/netvisu/2008/05/19/displaying-a-microsoft-project-xml-file-using-diagrammer-for-net-wpf-and-linq-part-1/#comments</comments>
		<pubDate>Mon, 19 May 2008 10:42:17 +0000</pubDate>
		<dc:creator>Emmanuel Tissandier</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[Diagram]]></category>

		<category><![CDATA[Linq]]></category>

		<category><![CDATA[WPF]]></category>

		<category><![CDATA[Diagrammer for .NET]]></category>

		<guid isPermaLink="false">http://blogs.ilog.com/netvisu/2008/05/19/displaying-a-microsoft-project-xml-file-using-diagrammer-for-net-wpf-and-linq-part-1/</guid>
		<description><![CDATA[Diagrammer for .NET 1.5 introduces a set of new WPF controls that can present information as a graph display made of nodes and links. In this post, I will show how you can use these controls to display the content&#8230;]]></description>
			<content:encoded><![CDATA[<p>Diagrammer for .NET 1.5 introduces a set of new WPF controls that can present information as a graph display made of nodes and links. In this post, I will show how you can use these controls to display the content of a Microsoft Project XML file. We will use .NET 3.5 and Linq to read the data and provide it to the ILOG WPF <strong>Diagram</strong> control.</p>
<p>The XML that you can export from Microsoft Project 2003 contains all the information on the project plan such as all the tasks, resources, calendars and more. Here we will only take care of the tasks and the predecessor constraints between tasks. Predecessor constraints are the constraints between tasks such as &#8220;task A starts after task B&#8221;. The graph that we will create will have nodes representing the tasks and links representing the predecessor constraints between tasks. The result will give something similar to the &#8220;Network Diagram&#8221; view of Microsoft Project that represents nicely the flow of tasks in the project plan.</p>
<p>First of all, a few words on the Microsoft Project XML format. The format defines a &lt;tasks&gt; tag that contains all the tasks, each task is represented by a &lt;task&gt; tag that contains the task information.</p>
<pre>
&lt;Project xmlns="http://schemas.microsoft.com/project"&gt;
...
&lt;Tasks&gt;
  &lt;Task&gt;
    &lt;UID&gt;Unique id of task&lt;/UID&gt;
    &lt;Name&gt;The name&lt;/Name&gt;
    &lt;Start&gt;The start date &lt;/Start&gt;
    &lt;Finish&gt;The finish date&lt;/Finish&gt;
     ...
    &lt;/Task&gt;
&lt;/Tasks&gt;
...
&lt;/Project&gt;</pre>
<p>When a task has predecessors, a &lt;PredecessorLink&gt; tag appears for each predecessor in the &lt;task&gt; tag:<br />
<code></code><code></code><code></code><code></p>
<pre>
&lt;Task&gt;
  ...
  &lt;PredecessorLink&gt;
    &lt;PredecessorUID&gt;1&lt;/PredecessorUID&gt;
    &lt;Type&gt;1&lt;/Type&gt;
  &lt;/PredecessorLink&gt;
  ...
&lt;/Task&gt;</pre>
<p>&lt;PredecessorUID&gt; corresponds to the unique id (UID tag) of the predecessor and &lt;Type&gt; gives the type of the constraint (0 for a &#8220;Finish to Finish&#8221; constraint, 1 for &#8220;Finish to Start&#8221;, 2 for &#8220;Start to Finish&#8221; and 3 for &#8220;Start to Start&#8221;).</p>
<p>That&#8217;s all we need to know to be able to read the data.</p>
<p>We now define very simple .NET classes that correspond to this structure, a class Project that represents the project, a Task and a PredecessorLink class:</p>
<pre>
public class Project
{
    public List&lt;Task&gt; Tasks { get; set; }
}  

public class PredecessorLink
{
    public int PredecessorUID { get; set; }
}  

public class Task
{
    public Project Project { get; set; }
    public int UID { get; set; }
    public string Name { get; set; }
    public DateTime Start { get; set; }
    public DateTime Finish { get; set; }
    public List&lt;PredecessorLink&gt; PredecessorLinks { get; set; }
}</pre>
<p>Thanks to Linq for XML, we can now read the data from the XML file and directly create the Project, Task and PredecessorLink instances.</p>
<pre>
XDocument document = XDocument.Load("./Engineering.xml");
Project project = new Project();
project.Tasks
      = (from task in document.Descendants("{http://schemas.microsoft.com/project}Task")
          where (int)task.Element("{http://schemas.microsoft.com/project}ID") != 0
          select new Task()
           {
               Project = project,
               UID = (int)task.Element("{http://schemas.microsoft.com/project}UID"),
               Name = (string)task.Element("{http://schemas.microsoft.com/project}Name"),
               Start = (DateTime)task.Element("{http://schemas.microsoft.com/project}Start"),
               Finish = (DateTime)task.Element("{http://schemas.microsoft.com/project}Finish"),
               PredecessorLinks =
                         (from link in task.Descendants("{http://schemas.microsoft.com/project}PredecessorLink")
                         select
                           new PredecessorLink
                           {
                               PredecessorUID = (int)link.Element("{http://schemas.microsoft.com/project}PredecessorUID")
                           }).ToList()  

              }).ToList();</pre>
<p>The LinQ code above will iterate over the &lt;Task&gt; elements in the XML document and create a Task instance, then for each Task he will create the list of PredecessorLink. Note that since the XML document defines a default namespace (http://schemas.microsoft.com/project), we need to specify this namespace when querying the document with Linq and this makes the code not really easy to read.</p>
<p>So far we have only been playing with data, we will now start to use WPF to render this information. We have a Project instance that contains a list of Task, each task containing information on its predecessors. That is almost all the information that is required to use the Diagrammer for .NET WPF Diagram control.</p>
<p>Let&#8217;s start the XAML code by using the <strong>Diagram</strong> control:</p>
<pre>
&lt;Window x:Class="CriticalPath.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ilog="http://www.ilog.com/diagrammer.net/2008"
    Title="Window1" Height="300" Width="300"&gt;
    &lt;Grid&gt;
        <strong>&lt;ilog:Diagram x:Name=&#8221;diagram&#8221;/&gt;</strong>
   &lt;/Grid&gt;
&lt;/Window&gt;</pre>
<p>We have named our control &#8220;diagram&#8221;, we can now specify the data source in the code behind:</p>
<pre>
  diagram.Source = project.Tasks;</pre>
<p>The diagram control now knows about the data source, but this information is not enough to create a graph display. At this point the result of the application is the following:<br />
<a href="http://blogs.ilog.com/netvisu/wp-content/uploads/2008/05/first.png" title="first.png"><img src="http://blogs.ilog.com/netvisu/wp-content/uploads/2008/05/first.png" alt="first.png" /></a><br />
Not so impressive&#8230;<br />
The Diagram control does not know the relation between the tasks and thus it has layout the task as a simple vertical list with no links between them. We have not defined any graphical representation for the nodes that&#8217;s why we get a simple rectangle with the name of the class (in this case this is the result of calling ToString() on the Task instances). Let&#8217;s make this look nicer.<br />
First we need to tell the Diagram that there are some relations between them. For this we use the <strong>PredecessorBinding</strong> property of the Diagram control.<br />
This <strong>PredecessorBinding</strong> property tells the control how from a Task (an item in the data source) he can find a list of predecessor Tasks (predecessor items in the data source). With this information, the Diagram control can create links between the nodes and layout the graph. So far the Task class does not have a property that returns the predecessor tasks, we only have the predecessor links. Let&#8217;s use LinQ again to create a property that returns the list of predecessor tasks:</p>
<pre>
public class Task
{
    public Project Project { get; set; }
    public int UID { get; set; }
    public string Name { get; set; }
    public DateTime Start { get; set; }
    public DateTime Finish { get; set; }
    public List&lt;PredecessorLink&gt; PredecessorLinks { get; set; }
    <strong>public List<task></task> Predecessors
    {
      get
      {
        return
          (from pred in PredecessorLinks
           join task in Project.Tasks on pred.PredecessorUID equals task.UID
           select task).ToList();
      }
    }</strong>
    public override string ToString()
    {
       return Name;
    }
}</pre>
<p>The new <strong>Predecessors</strong> property now returns the list of predecessor tasks by doing a LinQ join between the PredecessorUID in the PredecessorLink and the UID of tasks.</p>
<p>We can now change the XAML and use this new method:</p>
<pre>
    &lt;ilog:Diagram
        x:Name="diagram"
        <strong>PredecessorsBinding=&#8221;{Binding Predecessors}&#8221;</strong>&gt;</pre>
<p>Now the control knows about the relation between tasks. Note that we have also overridden the ToString method of the Task so that it returns the name of the task. Now we get the following graph that displays the constraints between tasks nicely layout:<br />
<a href="http://blogs.ilog.com/netvisu/wp-content/uploads/2008/05/second.png"><img src="http://blogs.ilog.com/netvisu/wp-content/uploads/2008/05/second1.png" /></a><br />
Now that the data is present, we can exercise our graphic designer skills using the styling and templating features of WPF to make this graph look better.<br />
The <strong>Diagram</strong> control has created instances of the <strong>Node</strong> and <strong>Link</strong> classes for nodes and links. We can then define a WPF style for these two classes:</p>
<pre>
&lt;Style TargetType="{x:Type ilog:Link}" &gt;
  &lt;Setter Property="Radius" Value="10"/&gt;
  &lt;Setter Property="Stroke" Value="#FFF0A5"/&gt;
  &lt;Setter Property="StrokeThickness" Value="2"/&gt;
  &lt;Setter Property="StartArrow"&gt;
    &lt;Setter.Value&gt;
      &lt;ilog:LinkArrow  Fill="White"  Shape="Circle"/&gt;
    &lt;/Setter.Value&gt;
  &lt;/Setter&gt;
  &lt;Setter Property="EndArrow"&gt;
    &lt;Setter.Value&gt;
      &lt;ilog:LinkArrow Fill="{x:Null}"  Shape="Open"/&gt;
    &lt;/Setter.Value&gt;
  &lt;/Setter&gt;
&lt;/Style&gt;  

&lt;Style TargetType="{x:Type ilog:Node}"&gt;
  &lt;Setter Property="Background" Value="#FFF0A5"/&gt;
  &lt;Setter Property="BorderBrush" Value="#468966"/&gt;
  &lt;Setter Property="BorderThickness" Value="1"/&gt;
&lt;/Style&gt;</pre>
<p>The style for link defines the color and thickness of links through the <strong>Stroke</strong> and <strong>StrokeThickness</strong> properties. It also defines a start and end arrow with different shapes. The style for nodes defines the colors for the background and border of the node.<br />
We are now going to display more information in the node that the simple name of the task. This is done through a WPF DataTemplate. The DataTemplate that we will specify through the <strong>NodeTemplate</strong> property of the <strong>Diagram</strong> control represents the graphical template that will be instantiated for each node. Here we will display not only the name but also the start and finish date of the task.</p>
<pre>
&lt;DataTemplate x:Key="TaskTemplate"&gt;
  &lt;Grid  Margin="5" MaxWidth="150" x:Name="grid"&gt;
    &lt;Grid.RowDefinitions&gt;
      &lt;RowDefinition/&gt;
      &lt;RowDefinition/&gt;
      &lt;RowDefinition/&gt;
    &lt;/Grid.RowDefinitions&gt;
    &lt;TextBlock
       x:Name="header" Grid.Row ="0"
       Text="{Binding Path=Name}"
       TextWrapping="WrapWithOverflow"
       Foreground="#FFB03B"
       FontWeight="Bold"/&gt;
    &lt;StackPanel x:Name="startField"  Grid.Row ="1" Orientation="Horizontal"&gt;
      &lt;TextBlock x:Name="startLabel" Text="Start:"/&gt;
      &lt;TextBlock Text="{Binding Path=Start}"/&gt;
    &lt;/StackPanel&gt;
    &lt;StackPanel x:Name="finishField" Grid.Row ="2" Orientation="Horizontal"&gt;
      &lt;TextBlock x:Name="finishLabel" Text="Finish:"/&gt;
      &lt;TextBlock Text="{Binding Path=Finish}"/&gt;
    &lt;/StackPanel&gt;
  &lt;/Grid&gt;
&lt;/DataTemplate&gt;</pre>
<p>This data template defines a grid with 3 rows, first row will display the name of the task, the second row the start date and the last row the finish date.</p>
<p>The Diagram control layouts the graph using a graph layout algorithm. ILOG Diagrammer for .NET provides a large set of graph layout algorithms that can be use to represents graph, in a Diagram the default algorithm is a Hierarchical layout algorithm. This algorithm suits perfectly for our needs because it shows nicely the flow of information in the graph. We will only modify some of the layout properties to get a nicer result. Let&#8217;s use orthogonal links and links evenly spaced on the side of nodes. We do this by specifying the layout algorithm through the <strong>GraphLayout</strong> property of the Diagram class in XAML.<br />
After adding a gradient for the background of the diagram through the Background property, the XAML is now:</p>
<pre>
&lt;ilog:Diagram
  NodeTemplate="{StaticResource TaskTemplate}"
  PredecessorsBinding="{Binding Predecessors}" x:Name="diagram"&gt;  

  &lt;!-- Background of diagram --&gt;
  &lt;ilog:Diagram.Background&gt;
    &lt;LinearGradientBrush  EndPoint="0.5,1" StartPoint="0.5,0"&gt;
      &lt;GradientStop Color="#FF555555" Offset="1"/&gt;
      &lt;GradientStop Color="#FF1C1C1C" Offset="0"/&gt;
    &lt;/LinearGradientBrush&gt;
  &lt;/ilog:Diagram.Background&gt;  

  &lt;!-- graph layout algorithm --&gt;
  &lt;ilog:Diagram.GraphLayout&gt;
    &lt;ilog:HierarchicalLayout
          LinkStyle="Orthogonal"
          ConnectorStyle="EvenlySpaced" /&gt;
  &lt;/ilog:Diagram.GraphLayout&gt;
&lt;/ilog:Diagram&gt;</pre>
<p>And the resulting graph is now much better.<br />
<a href="http://blogs.ilog.com/netvisu/wp-content/uploads/2008/05/criticalpath3.png"><img src="http://blogs.ilog.com/netvisu/wp-content/uploads/2008/05/criticalpath3.png" /></a></p>
<p>We have seen how easy it is to create a graph display using LinQ, WPF styling and templating and the Diagram control. In a second post I will show how you can go further and tailor the graph with WPF features such as data triggers and more features of the Diagram class. In particular, we will see how to display the critical path of the project plan.</p>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ilog.com/netvisu/2008/05/19/displaying-a-microsoft-project-xml-file-using-diagrammer-for-net-wpf-and-linq-part-1/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
