ToolBox and RadDiagramShape Style Width

3 posts, 1 answers
  1. B
    B avatar
    74 posts
    Member since:
    Jul 2011

    Posted 20 Jul 2015 Link to this post


    I can make my own RadDiagramShape Style:

    <Style TargetType="telerik:RadDiagramShape"
        <Setter Property="Width"
                Value="200" />
        <Setter Property="Height"
                Value="80" />
        <Setter Property="FontSize"
                Value="16" />
        <Setter Property="StrokeThickness"
                Value="1" />
        <Setter Property="BorderBrush"
                Value="Black" />
        <Setter Property="Stroke"
                Value="Black" />
        <Setter Property="Background">
                <LinearGradientBrush EndPoint="0.5,1"
                    <GradientStop Color="#FFB0B0FB"
                                  Offset="0" />
                    <GradientStop Color="#FF3C2ECA"
                                  Offset="0.527" />
                    <GradientStop Color="#FF746BCC"
                                  Offset="0.987" />
        <Setter Property="Foreground"
                Value="White" />

    <telerik:RadDiagram Grid.Row="1"
                        ShapeStyle="{StaticResource ShapeStyle}"
                        ConnectionStyle="{StaticResource ConnectionStyle}"


    <telerik:RadDiagramToolbox x:Name="MainToolBox"
                               IsEnabled="{Binding ActiveStructuur, Converter={StaticResource NullToBoolConverter}}"
                               IsOpen="False" />

    From code behind and the ToolBox these are respected: FontSize, StrokeThickness, BorderBrush, Stroke, Background.

    But not the width and height when I drag from the ToolBox.

    They are respected when I add the shape from code behind.

    Is there a way to make the ToolBox respect the width and height I specified in the style?



  2. Answer
    Martin avatar
    1044 posts

    Posted 21 Jul 2015 Link to this post

    Hello Baymar,

    The reported behavior is caused by the serialization behavior of the diagram. Basically, when you start dragging from the toolbox the dragged shape is serialized and when you drop it on the diagram surface a new one is created based on the serialization data (deserialization). There is a list of properties that are serialized by default - you can find it in the Serialization help article. When a property is serialized the diagram's internal logic set it as a local value and since setting a local value has bigger priority than a Style setter, the Width/Height from the style is not applied. 

    In order to apply the Width, Height and other properties from the default ones if necessary, you will need to set them to Null in the SerializationInfo when the serialization process starts. In your case, you can remove only the key value pair from the SerializationInfo dictionary which has its Key set to "Size". Here is an example:
    SerializationService.Default.ItemSerializing += Default_ItemSerializing;
    void Default_ItemSerializing(object sender, SerializationEventArgs<IDiagramItem> e)
        e.SerializationInfo["Size"] = null;

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft R3 2016 release webinar banner
  4. B
    B avatar
    74 posts
    Member since:
    Jul 2011

    Posted 21 Jul 2015 Link to this post

    Hi Martin,

    Great, that works perfectly.




Back to Top