controls in heirarchical data template - drag/tab behaviour

3 posts, 0 answers
  1. Trevor
    Trevor avatar
    8 posts
    Member since:
    Mar 2011

    Posted 24 Mar 2011 Link to this post

    Hi,

    I have a tree view control and in the data template of some of the nodes I have a text box to allow editing of internal settings. This works perfectly except for in two respects,

    1) if you try and select text within the text box with the mouse it starts a drag of the tree item. I would like a way to have the tree ignore the drag when the text box is the clicked on control.. If I return handled from the PreviewDragStarted event then the selection of text works correctly but I am unsure of a way to distinguish at this point where the original click occurred

    2) where I have more than one textbox in a data template I would like clicking 'tab' to move me to the next textbox, not the tree control itself/next control on page. I have played with the KeyboardNavigation.TabNavigation settings but not found anything that worked..

    any thoughts appreciated.
  2. Trevor
    Trevor avatar
    8 posts
    Member since:
    Mar 2011

    Posted 24 Mar 2011 Link to this post

    Have resolved 1) with the following check in preview drag started:

                if (Keyboard.FocusedElement as TextBox != null)
                    e.Handled = true;

    but still need a hand with 2..
  3. UI for WPF is Visual Studio 2017 Ready
  4. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 30 Mar 2011 Link to this post

    Hi Trevor,

    If you use ItemEditTemplate the tab navigation from the first textbox to the second will work out of the box:
    <Grid.Resources>
              <DataTemplate x:Key="itemEditTemplate">
                  <StackPanel Orientation="Horizontal">
                      <TextBox Width="100" Text="Alpha" />
                      <Rectangle Fill="DeepSkyBlue" Width="2" />
                      <TextBox Width="100" Text="Alpha" />
                  </StackPanel>      
              </DataTemplate>
          </Grid.Resources>
          <telerik:RadTreeView x:Name="treeView"
                               IsEditable="True"
                               ItemEditTemplate="{StaticResource itemEditTemplate}">            
          </telerik:RadTreeView>
    If you use ItemTemplate istead of ItemEditTemplate, you will have to deal with tab navigation programatically like so:
    <Grid.Resources>
            <DataTemplate x:Key="itemTemplate">
                <StackPanel Orientation="Horizontal">
                    <TextBox Width="100" Text="Alpha" x:Name="leftBox" KeyDown="leftBox_KeyDown"/>
                    <Rectangle Fill="DeepSkyBlue" Width="2" />
                    <TextBox Width="100" Text="Alpha" x:Name="rightBox"/>
                </StackPanel>      
            </DataTemplate>
        </Grid.Resources>
        <telerik:RadTreeView x:Name="treeView" ItemTemplate="{StaticResource itemTemplate}" />
    private void leftBox_KeyDown(object sender, KeyEventArgs e)
          {
              if (e.Key == Key.Tab)
              {
                  ((sender as TextBox).Parent as StackPanel).ChildrenOfType<TextBox>()[1].Focus();
                  e.Handled = true;
              }
          }
    Feel free to ask if you need further assistance.

    Best wishes,
    Petar Mladenov
    the Telerik team
Back to Top