This is a migrated thread and some comments may be shown as answers.

ToolBox and RadDiagramShape Style Width

2 Answers 148 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
B
Top achievements
Rank 2
B asked on 20 Jul 2015, 11:49 AM

Hi,

I can make my own RadDiagramShape Style:

<Style TargetType="telerik:RadDiagramShape"
       x:Key="ShapeStyle">
    <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">
        <Setter.Value>
            <LinearGradientBrush EndPoint="0.5,1"
                                 StartPoint="0.5,0">
                <GradientStop Color="#FFB0B0FB"
                              Offset="0" />
                <GradientStop Color="#FF3C2ECA"
                              Offset="0.527" />
                <GradientStop Color="#FF746BCC"
                              Offset="0.987" />
            </LinearGradientBrush>
        </Setter.Value>
    </Setter>
    <Setter Property="Foreground"
            Value="White" />
</Style>

<telerik:RadDiagram Grid.Row="1"
                    IsRotationEnabled="False"
                    AllowDrop="True"
                    SelectionChanged="MainDiagram_SelectionChanged"
                    ShapeStyle="{StaticResource ShapeStyle}"
                    ConnectionStyle="{StaticResource ConnectionStyle}"
                    ConnectionBridge="Gap"
                    IsPanEnabled="True"
                    x:Name="MainDiagram"> 

 

<telerik:RadDiagramToolbox x:Name="MainToolBox"
                           IsEnabled="{Binding ActiveStructuur, Converter={StaticResource NullToBoolConverter}}"
                           HorizontalAlignment="Stretch"
                           Title="Gallery"
                           Header="ToolBox"
                           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?

Regards,

Bayram

2 Answers, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 21 Jul 2015, 10:04 AM
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;
}


Regards,
Martin
Telerik
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
0
B
Top achievements
Rank 2
answered on 21 Jul 2015, 10:17 AM

Hi Martin,

Great, that works perfectly.

Regards,

Bayram

 

Tags
Diagram
Asked by
B
Top achievements
Rank 2
Answers by
Martin Ivanov
Telerik team
B
Top achievements
Rank 2
Share this question
or