Overriding Diagram Events

5 posts, 1 answers
  1. Michael
    Michael avatar
    8 posts
    Member since:
    Sep 2011

    Posted 17 Jul 2012 Link to this post

    Hi,

    I have a few of questions but they all stem around the question of how to intercept and handle certain events from the diagram.

    1. I have a case where I need to intercept when the 'Tab' key is pressed while the diagram is in focus. Is this possible? 
    2. I have another case where I introduced a custom shape that is really just a text box. Currently it takes three clicks before I can actually edit the text in the box of the shape. One click to select the shape, another to signify I want to edit the text in the box, and the third click, i'm not sure about. Regardless I would like to trigger the editing of the text in the box after one click. If I override the shapeclicked event how do I get the contained shape into edit mode?
    3. The final question revolves around the same text box shape. The text box is supposed to accept returns, but for some reason when I press return while editing the textbox something (the diagram) intercepts the return key and finishes the edit. Can I override this behaviour?

    Below is the xaml I have used for the text box shape style. Its pretty basic and I took it pretty much straight from your Dashboard Designer example.


        <Style TargetType="local:ASTextBoxShape" BasedOn="{StaticResource RadDiagramShapeStyle}">
            <Setter Property="Background" Value="Wheat" />
            <Setter Property="BorderBrush" Value="Black" />
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <Setter Property="VerticalContentAlignment" Value="Stretch" />
            <Setter Property="ContentTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <TextBlock Grid.Row="1" Grid.Column="1"
                  Text="{Binding Path=Text, Mode=TwoWay, RelativeSource={RelativeSource AncestorType=local:ASTextBoxShape}}"
                  Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType=local:ASTextBoxShape}}"
                  Margin="0,0,0,0" TextWrapping="Wrap" MaxWidth="800"
                  FontSize="{Binding Path=FontSize, RelativeSource={RelativeSource AncestorType=local:ASTextBoxShape}, Mode=TwoWay}"
                  FontWeight="{Binding Path=FontWeight, RelativeSource={RelativeSource AncestorType=local:ASTextBoxShape}}" />
                    </DataTemplate>
                </Setter.Value>
            </Setter>
     
            <Setter Property="EditTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <TextBox  
                    Text="{Binding Path=Text,Mode=TwoWay, RelativeSource={RelativeSource AncestorType=local:ASTextBoxShape}}"
                    Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType=local:ASTextBoxShape}}"
                    Margin="0,0,0,0" TextWrapping="Wrap" MaxWidth="800"
                    FontSize="{Binding Path=FontSize, RelativeSource={RelativeSource AncestorType=local:ASTextBoxShape}, Mode=TwoWay}"
                    FontWeight="{Binding Path=FontWeight, RelativeSource={RelativeSource AncestorType=local:ASTextBoxShape}}" />
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    


  2. Lancelot
    Lancelot avatar
    251 posts
    Member since:
    Jul 2012

    Posted 18 Jul 2012 Link to this post

    Hi Michael,

    The RadDiagrammingFramework has many events. This link will bring you to the list of events in the Diagram itself and this link will bring you to the list if events for the Items themselves.

    You may also find this link helpful. Scroll to the bottom to see the section on items selection and the events surrounding it.

    While you're in there looking at the links I've provided, glance over to the left pane and scroll down. Notice the expanded node. There is a lot of documentation for RadDiagram that contains descriptions and example code.

    Good Luck,
    Lancelot
  3. DevCraft banner
  4. Michael
    Michael avatar
    8 posts
    Member since:
    Sep 2011

    Posted 18 Jul 2012 Link to this post

    Thank you for the quick response. I'm still confused about a couple things:

    1) Is it possible to catch the 'Tab' Key? I didn't see any events in the documentation that will allow for this.

    2) The text box shape is supposed to accept returns, but for some reason when I press return while editing the textbox, something (the diagram I presume) intercepts the return key and finishes the edit. How exactly do I override this? Should I be overriding the endedit ? Sorry but I'm sure how to resolve this.

    Any further suggestions are appreciated.
  5. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 20 Jul 2012 Link to this post

    Hi Michael,

    You can handle the RadDiagram.KeyDown event to intercept the Tab key being hit:
      <telerik:RadDiagram KeyDown="RadDiagram_KeyDown">
              <local:ASTextBoxShape />
    </telerik:RadDiagram>
    private void RadDiagram_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Tab)
        {
                     //enter your logic
        }
    }
     
    However, the Multiline issue is a bug and this is why I logged it in our PITS where you can track its progress. I also updated your Teleirk account for bringing it to our attention.

    Kind regards,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Michael
    Michael avatar
    8 posts
    Member since:
    Sep 2011

    Posted 20 Jul 2012 Link to this post

    Now I feel like an idiot! Key down event what a concept.

    Thanks every so much for your excellent continued support.

Back to Top
DevCraft banner