Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
80
Content alignment inside XamDiagramToolbox
posted

Hi,

I am attempting to create a custom toolbox containing custom shapes. I am having some issues controlling the content alignment inside those shapes when they are in the toolbox, and also when they are on a xamDiagram.

An example of a shape:

Public Class ResolveFork
Inherits DiagramNode

Public Sub New()

NodeType = NodeType.Circle
Stroke = Brushes.HotPink
StrokeThickness = 3
Fill = Brushes.Transparent
FontBrush = Brushes.DarkGreen
Content = "Fork"
Width = 40
Height = 40
HorizontalContentAlignment = HorizontalAlignment.Right

End Sub

Public Overrides Function Clone() As Infragistics.Controls.Charts.DiagramItem

Return New ResolveFork

End Function

End Class

This shape is added to the Toolbox as follows:

Categories(0).ToolboxCategoryItems.Add(New DiagramToolboxItem With {.Title = "My shape" & " LABEL", .Item = New ResolveFork})

When this runs, in the Toolbox the content ("Fork") is aligned left. When the shape is dragged onto the xamDiagram, the content is centred.

How do I get the content to align right in both circumstances?

Regards

David

  • 995
    Verified Answer
    posted

    Hello David,

    There is currently a known issue with the horizontal alignment, which is going to be fixed in the next version.

    Meanwhile I suggest you use a custom ContentTemplate for your ResolveFork nodes. This template can contain a right-aligned textblock. Additionally the content template is applied in the Clone method override.

    Below is the code for the ResolveFork class:

    Public Class ResolveFork
    	Inherits DiagramNode
    	Private Shared _contentTemplate As DataTemplate
    	Shared Sub New()
    		Dim fef As New FrameworkElementFactory(GetType(TextBlock))
    		Dim b As New Binding()
    		fef.SetBinding(TextBlock.TextProperty, b)
    		fef.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Right)
    		_contentTemplate = New DataTemplate()
    		_contentTemplate.VisualTree = fef
    	End Sub
    
    	Public Sub New()
    		NodeType = NodeType.Circle
    		Stroke = Brushes.HotPink
    		StrokeThickness = 3
    		Fill = Brushes.Transparent
    		FontBrush = Brushes.DarkGreen
    		Content = "Fork"
    		ContentTemplate = _contentTemplate
    		Width = 40
    		Height = 40
    	End Sub
    
    	Public Overrides Function Clone() As DiagramItem
    		Dim clone1 = TryCast(MyBase.Clone(), DiagramNode)
    		clone1.ContentTemplate = _contentTemplate
    		Return clone1
    	End Function
    End Class
    

    Let me know if you need further assistance.

    Regards,
    Philip