RadDiagramTextShape - the same font size in edit and normal mode

4 posts, 0 answers
  1. Adam
    Adam avatar
    3 posts
    Member since:
    May 2016

    Posted 23 Jul Link to this post

    Hello,

    I having problem with RadDiagramTextShape font size when it is editing. I need to RadDiagramTextShape font size in edit mode is equal to font size in normal state. I don't see any relationship between the font size in normal mode and edit mode (see attach file). I think currently font size is fixed value in edit mode. 

    How I can binding/set size font in edit mode to equal in normal mode?

     

    Thanks you

    Adam

  2. Peshito
    Admin
    Peshito avatar
    497 posts

    Posted 27 Jul Link to this post

    Hi Adam,

    In order to have equal sizes for the RadDiagramTextShape's font size and the one used in edit mode, use the EditTemplate property of the shape. For instance:
    <telerik:RadDiagram x:Name="diagram">
                <telerik:RadDiagramTextShape Content="This is a text shape" Position="20, 40" FontSize="24">
                    <telerik:RadDiagramTextShape.EditTemplate>
                        <DataTemplate>
                            <TextBlock
                                FontSize="{Binding RelativeSource={RelativeSource AncestorType=telerik:RadDiagramTextShape}, Path=FontSize}"
                                Text="{Binding}"/>
                        </DataTemplate>
                    </telerik:RadDiagramTextShape.EditTemplate>
                     
                </telerik:RadDiagramTextShape>
                <telerik:RadDiagramShape Content="this is a simple shape" Position="40, 80">
                     
                </telerik:RadDiagramShape>
            </telerik:RadDiagram>
    I am binding the font size of the TextBlock in my DataTemplate to the font size of the RadDiagramShape's element.

    Hope this helps.

    Regards,
    Peshito
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Adam
    Adam avatar
    3 posts
    Member since:
    May 2016

    Posted 09 Aug in reply to Peshito Link to this post

    Hi Peshito,

    Thank you for this code. Why do you use TextBlock in DataTemplate? When I use TextBlock in DataTemplate I can't edit RadDiagramTextShape (after double click RadDiagramTextShape change to not editable TextBlock). I change it to TextBox and it is working now, but TextBox isn't focused after double click and cursor isn't at the end of editable TextBox. How can I change it? 

     

    <DataTemplate>
            <TextBox TextWrapping="Wrap" AcceptsReturn="True"
                                FontSize="{Binding RelativeSource={RelativeSource AncestorType=telerik:RadDiagramTextShape}, Path=FontSize}"
                                Text="{Binding RelativeSource={RelativeSource AncestorType=telerik:RadDiagramTextShape}, Path=Content}"/>
    </DataTemplate>

  5. Peshito
    Admin
    Peshito avatar
    497 posts

    Posted 10 Aug Link to this post

    Hello Adam,

    I have mistaken the TextBlock with the TextBox in the DataTemplate. This approach seems not to be the best one. Using shape's EditTemplate will require further work to mimic the default diagram's behavior for the shape because this way a whole new custom template will be used. This is why I would suggest another one. Simply attach to shape's loaded event as shown below:
    private void RadDiagramTextShape_Loaded(object sender, RoutedEventArgs e)
    {
            RadDiagramTextShape shape = sender as RadDiagramTextShape;
            TextBox tBox = shape.ChildrenOfType<TextBox>().FirstOrDefault();
            tBox.FontSize = shape.FontSize;
    }
    This way the DiagramTextShape will act as if the FontSize was changing correctly in edit mode. I logged this as a bug report in our feedback portal. Here is the link where you can follow its progress and vote for it in order to rise its priority.

    Regards,
    Peshito
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top