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

BeginEdit() clears item's header

3 Answers 58 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 06 Jan 2017, 02:47 PM

With version 2016 Q3 SP1 a RadTreeViewItem's Header is being emptied when I initiate editig with radTreeView.SelectedContainer.BeginEdit(). According to other posts in this forum this seems to be a previously known and corrected issue. Obviously it is back again.

Is there anything I can do to work around this issue?

Thanks

Michael

3 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 09 Jan 2017, 08:18 AM
Hi Michael,

Please check out test project attached. Select an item and then click the button. EditTemplate is being applied and the editable text is selected. Please feel free to modify the project in order to replicate your scenario. We would be glad to investigate it further. Thank you in advance.

Regards,
Petar Mladenov
Telerik by Progress
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
Michael
Top achievements
Rank 1
answered on 09 Jan 2017, 02:00 PM

Hi Petar,

instead of providing a DataTemplate I've changed your xaml code to using a style for RadTreeViewItem. You can easily reproduce the issue with this xaml code:

 

<Grid>
    <Grid.Resources>
 
        <!--HierarchicalDataTemplate x:Key="template2" ItemsSource="{Binding Children}">
            <Grid>
                <TextBlock Text="{Binding Name}"/>
            </Grid>
        </HierarchicalDataTemplate>
 
        <HierarchicalDataTemplate x:Key="template" ItemsSource="{Binding Children}" ItemTemplate="{StaticResource template2}">
            <Grid>    
                <TextBlock Text="{Binding Name}"/>
            </Grid>
        </HierarchicalDataTemplate-->
 
        <Style TargetType="telerik:RadTreeViewItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <Setter Property="IsExpanded" Value="true" />
            <Setter Property="Header" Value="{Binding Name}" />
            <Setter Property="ItemsSource" Value="{Binding Children}" />
        </Style>
    </Grid.Resources>
 
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
 
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
 
        <!-- ItemTemplate="{StaticResource template}"  -->
        <telerik:RadTreeView IsVirtualizing="True" IsLineEnabled="True"
                             IsRootLinesEnabled="False" IsEditable="True"
                         SelectionMode="Extended" Height="400"
                         x:Name="tree"
                        telerik:TextSearch.TextPath="Name"
                         VerticalAlignment="Top" >
 
        </telerik:RadTreeView>
        <Button VerticalAlignment="Bottom" HorizontalAlignment="Center" Content="this.tree.SelectedContainer.BeginEdit();" Click="Button_Click"/>
    </Grid>
 
</Grid>

 

Regards
Michael

0
Accepted
Petar Mladenov
Telerik team
answered on 10 Jan 2017, 08:55 AM
Hello Michael,

The truth is RadTreeView is designed to work with HierarchicalDataTemplates (HDT) when databound in 95 % of all scenarios. Also, HDT is class strictly designed by MS to support HeaderedItemsControls which RadTreeViewItem is. Is there any specific reason you don't use it ?

When you set ItemsSource both on RadTreeViewItems and RadTreeView and you don't set ItemTemplate, the way ItemEditTemplate is evaluated is different than normal and the default TextBox from the default ImteEditTemplate receives different datacontext. A possible way to work this around is to set this edittemplate:

<DataTemplate x:Key="editTemplate">
              <TextBox Text="{Binding Path=DataContext.Name, Mode=TwoWay, RelativeSource={RelativeSource AncestorType=telerik:RadTreeViewItem}}" />
          </DataTemplate>
 
<telerik:RadTreeView IsVirtualizing="True"
                               IsLineEnabled="True"
                               IsRootLinesEnabled="False"
                               IsEditable="True"
                               ItemEditTemplate="{StaticResource editTemplate}"

However, we encourage you to use HDTs as more reliable having in mind all possible features they support - selectors, inheritance, etc.

Regards,
Petar Mladenov
Telerik by Progress
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
TreeView
Asked by
Michael
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Michael
Top achievements
Rank 1
Share this question
or