Northwoods.GoWPF 2.2.4 Assembly
Part Class
Members 

A Part is an item in a Diagram's Panel's Layer, corresponding to data representing a node or a link.
Syntax
Remarks

There are two classes inheriting from this abstract class: Node and Link.

Each Part can only be a child element of a Layer: either a NodeLayer or a LinkLayer. Parts cannot be nested in the visual tree. However, a subclass of node, Group, supports the logical nesting of nodes (and links) as members of a group. You can specify which layer a part should be in by setting its LayerName property.

A Part is typically created by the Diagram's PartManager in response to the presence or addition of some data to the diagram's Model. The part manager creates the node or link, sets its Content property to the data (indirectly) and its ContentTemplate property to a DataTemplate based on the type of part and the part's Category. The FrameworkElement that results from the application of the template to the data is accessible as the VisualElement property.

Each part has a Bounds property that describes its position and size in model coordinates. This property is read-only. One can change the bounds of a Node by setting its Location or Node.Position property.

A part can be selected or de-selected by setting its IsSelected property.

Most of the properties pertinent to parts are attached dependency properties rather than regular dependency properties. Many are only to be used on the VisualElement, not on the part itself nor on nested elements in the part's visual tree. The reason for using attached properties is to make it easier to data bind those properties in the data template.

An example is the LayerNameProperty. Consider the following data template for nodes: <DataTemplate x:Key="ExampleTemplate"> <Border Background="White" BorderBrush="Blue" BorderThickness="2" CornerRadius="3" Padding="2,0,2,0" go:Node.LayerName="{Binding Path=Data.LayerName}"> <TextBlock Text="{Binding Path=Data.Name}" /> </Border> </DataTemplate> The example assumes that the node data to which each node is bound has at least two properties: one named "Name" holding the text to be displayed, and one named "LayerName" specifying the name of the Layer that the node should be in. Note that setting the attribute for the layer name refers to the attached property qualified by the class name ("Node" in this case, in the XMLNS namespace referenced by "go").

The LayerName CLR property of Part gets and sets the value of the LayerNameProperty on the part's VisualElement. Please be aware that such property getters will just return the default value for the property when the data template has not yet been applied, as will be the case when VisualElement is null. Such property setters will try applying the template if needed before actually setting the attached property on the VisualElement.

Note that the data binding goes indirectly through a property named "Data": <TextBlock Text="{Binding Path=Data.Name}" /> This is because the part's Content is not the data itself but a simple data structure that includes the data as its PartManager.PartBinding.Data property. The other property refers to the Part itself. This permits bindings such as: <DataTrigger Binding="{Binding Path=Part.IsSelected}" Value="True" > <Setter Property="Border.BorderBrush" Value="Red" /> <Setter Property="go:Node.LayerName" Value="Foreground" /> </DataTrigger> This results in the border's brush changing color when the node is selected, and in the node being moved to the foreground layer when it is selected. (This requires corresponding changes to the Border element, since the BorderBrush and go:Node.LayerName properties should not be set locally if they want to be modified in a style trigger.) (Also note that this example will not work in Silverlight.)

There are many properties, named "...able", that control what operations the user may perform on this part. These properties correspond to the same named properties on Diagram and Layer that govern the behavior for all parts in all layers or for all parts in the given layer. For example, the Copyable property corresponds to the properties AllowCopy and AllowCopy.

For each of these "ability" properties there is a corresponding "Can..." predicate. For example, the CanCopy predicate is false if any of the three previously named properties is false.

As previously mentioned, Diagram supports the notion of selected parts. The part class also supports showing visual objects for a part when it gets selected. These visuals are typically used to show that the part is selected ("selection handles") or are used to allow the user to manipulate or modify the part with a tool ("tool handles"). These handles are the visual elements of Adornment nodes. The UpdateAdornments method is responsible for showing or hiding adornments, normally depending on whether the part is selected.

When the SelectionAdorned (attached) property is true, a selected part automatically gets an Adornment node created for it. Such a node gets a ContentTemplate property that is the value of SelectionAdornmentTemplate. (If the value is null, a default selection adornment template is used.) If the node is bound to data, the adornment is also bound to the same data.

Tool handles are shown for those tools that need it. The process of updating adornments for a part will ask each mode-less tool to Northwoods.GoXam.Tool.IDiagramTool.UpdateAdornments. Most tools might not need special tool handles. But, for example, Northwoods.GoXam.Tool.ResizingTool naturally will want to create an adornment with eight resize handles positioned at the corners and at the middles of the sides of the selected node's visual element, if the node has CanResize returning true.

However one does not always want the whole part to get the selection handle and any tool handles. Sometimes one wants to emphasize selection by highlighting a particular element within the part's visual tree. This can be achieved by setting the SelectionElementName property, and making sure the desired element has the same x:Name attribute value. For example, the following node template causes resize handles to appear surrounding the Rectangle element, not around the whole node. <DataTemplate x:Key="ExampleTemplate"> <StackPanel go:Node.Resizable="True" go:Node.SelectionElementName="myIcon"> <Rectangle x:Name="myIcon" Width="30" Height="30" Fill="LightSalmon" Stroke="Maroon" StrokeThickness="2" /> <TextBlock Text="{Binding Path=Data.Name}" HorizontalAlignment="Center" /> </StackPanel> </DataTemplate>

There are some methods for finding and examining particular elements in the part's visual tree: FindDescendant, FindNamedDescendant, IsVisibleElement, GetRelativeElementPoint, GetElementPoint, and GetElementBounds.

There are other methods and properties for looking at the relationships between parts: IsTopLevel, FindTopLevelPart, IsContainedBy(Part), ContainingSubGraph, and FindCommonContainingSubGraph(Part).

You may not apply any transforms to a Part; that is reserved to GoXam for future use.

Inheritance Hierarchy

System.Object
   System.Windows.Threading.DispatcherObject
      System.Windows.DependencyObject
         System.Windows.Media.Visual
            System.Windows.UIElement
               System.Windows.FrameworkElement
                  System.Windows.Controls.ContentPresenter
                     Northwoods.GoXam.Part
                        Northwoods.GoXam.Link
                        Northwoods.GoXam.Node

Requirements
See Also

Reference

Part Members
Northwoods.GoXam Namespace

 

 


© Northwoods Software 2017. All Rights Reserved.

Send Feedback