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

Overriding Diagram Events

4 Answers 110 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Michael
Top achievements
Rank 1
Michael asked on 18 Jul 2012, 03:16 AM
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>


4 Answers, 1 is accepted

Sort by
0
Lancelot
Top achievements
Rank 1
answered on 18 Jul 2012, 07:07 PM
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
0
Michael
Top achievements
Rank 1
answered on 18 Jul 2012, 09:40 PM
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.
0
Accepted
Tina Stancheva
Telerik team
answered on 20 Jul 2012, 12:09 PM
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.

0
Michael
Top achievements
Rank 1
answered on 20 Jul 2012, 06:24 PM
Now I feel like an idiot! Key down event what a concept.

Thanks every so much for your excellent continued support.

Tags
Diagram
Asked by
Michael
Top achievements
Rank 1
Answers by
Lancelot
Top achievements
Rank 1
Michael
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or