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

Erreur inserting Text in Diagram

3 Answers 59 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Valentin
Top achievements
Rank 1
Iron
Iron
Valentin asked on 23 Apr 2018, 08:30 AM

Hi Telerik,

 

I'm using a custom RadDiagramTextShape in RadDiagram :

<Style TargetType="diagramscontrols:RadDiagramTextShape">
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="BorderBrush" Value="Transparent"/>
    <Setter Property="StrokeThickness" Value="1"/>
    <Setter Property="RenderTransformOrigin" Value="0.5 0.5"/>
    <Setter Property="FontSize" Value="{StaticResource DiagramShapeFontSize}"/>
    <Setter Property="FontFamily" Value="Segoe UI"/>
    <!--<Setter Property="TextBlock.TextAlignment" Value="{Binding Tag.HorizontalTextAlignement, RelativeSource={RelativeSource AncestorType=diagramscontrols:RadDiagramTextShape}}"/>
    <Setter Property="TextBlock.TextWrapping"  Value="Wrap"/>-->
    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    <Setter Property="VerticalContentAlignment" Value="Stretch"/>
    <Setter Property="diagrams:DiagramBehaviors.TextWrapping" Value="Wrap"/>
    <Setter Property="ZIndex" Value="2"/>
    <Setter Property="Padding" Value="4"/>
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="diagramscontrols:RadDiagramTextShape">
                <Grid UseLayoutRounding="True">
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="MouseStates">
                            <VisualState x:Name="Normal"/>
                            <VisualState x:Name="MouseOver"/>
                        </VisualStateGroup>
                        <VisualStateGroup x:Name="ActiveConectionStates">
                            <VisualState x:Name="NormalActiveConnectionState"/>
                            <VisualState x:Name="ActiveConnectionInsideShape">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="ActiveSelectedBorder" Storyboard.TargetProperty="Visibility">
                                        <DiscreteObjectKeyFrame KeyTime="0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <Visibility>Visible</Visibility>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                        <VisualStateGroup x:Name="ConnectorsAdornerVisibilityStates">
                            <VisualState x:Name="ConnectorsAdornerCollapsed"/>
                            <VisualState x:Name="ConnectorsAdornerVisible">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="ConnectorsControl" Storyboard.TargetProperty="Visibility">
                                        <DiscreteObjectKeyFrame KeyTime="0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <Visibility>Visible</Visibility>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                        <VisualStateGroup x:Name="SelectionStates">
                            <VisualState x:Name="Selected"/>
                            <VisualState x:Name="SelectedInGroup">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="SelectedInGroupBorder" Storyboard.TargetProperty="Visibility">
                                        <DiscreteObjectKeyFrame KeyTime="0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <Visibility>Visible</Visibility>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Unselected"/>
                            <VisualState x:Name="SelectedAsGroup"/>
                        </VisualStateGroup>
                        <VisualStateGroup x:Name="EditMode">
                            <VisualState x:Name="NormalMode">
 
                            </VisualState>
                            <VisualState x:Name="NormalEditMode">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="NormalContent" Storyboard.TargetProperty="Visibility">
                                        <DiscreteObjectKeyFrame KeyTime="0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <Visibility>Collapsed</Visibility>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="EditContent" Storyboard.TargetProperty="Visibility">
                                        <DiscreteObjectKeyFrame KeyTime="0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <Visibility>Visible</Visibility>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="TextBoxEditMode">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="NormalContent" Storyboard.TargetProperty="Visibility">
                                        <DiscreteObjectKeyFrame KeyTime="0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <Visibility>Collapsed</Visibility>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="EditTextBox" Storyboard.TargetProperty="Visibility">
                                        <DiscreteObjectKeyFrame KeyTime="0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <Visibility>Visible</Visibility>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <Grid>
                        <Border Background="{TemplateBinding Background}" Visibility="Visible" BorderThickness="{Binding ElementName=RectangleBorder, Path=StrokeThickness, FallbackValue=1}">
                            <Border.BorderBrush>
                                <VisualBrush>
                                    <VisualBrush.Visual>
                                        <Rectangle StrokeDashArray="{TemplateBinding StrokeDashArray}" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="{TemplateBinding StrokeThickness}"
                                                   Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type Border}}, Path=ActualWidth}"
                                                   Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type Border}}, Path=ActualHeight}"
                                                   x:Name="RectangleBorder"/>
                                    </VisualBrush.Visual>
                                </VisualBrush>
                            </Border.BorderBrush>
                        </Border>
 
                        <Border x:Name="SelectedInGroupBorder" Visibility="Collapsed" BorderBrush="{StaticResource DiagramShape_Selected_BorderBrush}" BorderThickness="2"/>
                        <Border x:Name="ActiveSelectedBorder" Visibility="Collapsed" BorderBrush="{StaticResource DiagramShape_ActiveSelected_BorderBrush}" BorderThickness="2"/>
 
                        <TextBlock x:Name="NormalContent" Margin="{TemplateBinding Padding}"
                                       HorizontalAlignment="{Binding Tag.HorizontalTextAlignement, RelativeSource={RelativeSource AncestorType=diagramscontrols:RadDiagramTextShape}}"
                                       TextAlignment="{Binding Tag.TextAlignement, RelativeSource={RelativeSource AncestorType=diagramscontrols:RadDiagramTextShape}}"
                                       VerticalAlignment="Center"  diagrams:DiagramBehaviors.TextWrapping="Wrap" TextWrapping="Wrap" Text="{TemplateBinding Content}"/>
 
                        <primitives:ConnectorsControl x:Name="ConnectorsControl" ItemsSource="{TemplateBinding Connectors}" Visibility="Collapsed"
                                                          ItemContainerStyle="{TemplateBinding ConnectorStyle}"/>
                    </Grid>
                    <Grid x:Name="PART_RotationalPart" Margin="2">
                        <ContentPresenter x:Name="EditContent"
                            Visibility="Collapsed"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            Content="{TemplateBinding Content}"
                            ContentTemplate="{TemplateBinding EditTemplate}" />
                        <TextBox x:Name="EditTextBox" BorderThickness="0" Margin="0" Style="{StaticResource EditTextBoxStyle}" VerticalAlignment="Stretch" Visibility="Collapsed">
                            <TextBox.InputBindings>
                                <KeyBinding Key="Enter" Command="ApplicationCommands.NotACommand"/>
                            </TextBox.InputBindings>
                        </TextBox>
                    </Grid>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
 
<Style TargetType="TextBox" x:Key="EditTextBoxStyle">
    <Setter Property="TextWrapping" Value="Wrap"/>
    <Setter Property="AcceptsReturn" Value="True"/>
    <Setter Property="TextAlignment" Value="Center"/>
    <Setter Property="HorizontalAlignment" Value="Stretch"/>
    <Setter Property="VerticalAlignment" Value="Center"/>
    <Setter Property="Margin" Value="4"/>
    <Setter Property="FontSize" Value="11"/>
    <Setter Property="FontFamily" Value="Segoe UI"/>
    <Setter Property="Foreground" Value="Black"/>
    <Setter Property="Padding" Value="2"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="TextBox">
                <Grid x:Name="RootElement" UseLayoutRounding="True">
                    <Rectangle Stroke="{StaticResource DiagramShape_EditTextBox_BorderBrush}" StrokeDashArray="3 3" Fill="{StaticResource DiagramShape_EditTextBox_Background}"/>
                    <ScrollViewer
                            Padding="{TemplateBinding Padding}"
                            BorderThickness="0"
                            Background="Transparent"
                            Foreground="{TemplateBinding Foreground}"
                            VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                            HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                            x:Name="PART_ContentHost"/>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

 

My nominal scenario is :

1- Select Text tool

2- Select size of the shape (drag the mouse in the diagram)

3-  Write text in the TextBlock in the shape

4- Open settings of the shape, and select Background and BorderBrush

5- Shape is saved (with Serialization and after in database)

 

The problem is when I'm going in settings (step 4) without wrote text (step 3). In this case, the shape is unusable (If I click on it, I can't update the text), and not saved (when I leave the diagram and go back, the shape isn't here).

I can't access to fired events and I don't know where come from this problem.

 

Can you help me ?

 

Thank you.

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Petar Mladenov
Telerik team
answered on 26 Apr 2018, 08:12 AM
Hi Valentin ,

This is known issue and we have previously logged it in our portal. Please check it in the link below and let us know if the suggested workaround and the expected behavior (after fix in future) is suitable for you.
Regards,
Petar Mladenov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Valentin
Top achievements
Rank 1
Iron
Iron
answered on 26 Apr 2018, 10:27 AM

Hi Petar,

 

Thank for this links, it's work for me ! 

Can you explain why if the text is empty or equals to "space", the behaviour is defective ? This is to understand.

 

Thank you again.

0
Petar Mladenov
Telerik team
answered on 30 Apr 2018, 10:07 AM
Hi Valentin,

Basically our TextTool mimics the behavior of the MS Visio Text Tool. If text shape has no text or text with spaces only, it is removed from the diagram surface. We have missed the case when background is set on empty text shape. In Visio, such shape remains in the surface. So probably this will be the behavior we will implement when fixing the issue.

Regards,
Petar Mladenov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
Diagram
Asked by
Valentin
Top achievements
Rank 1
Iron
Iron
Answers by
Petar Mladenov
Telerik team
Valentin
Top achievements
Rank 1
Iron
Iron
Share this question
or