Binding AllowDrop in custom control in radtreeview

7 posts, 0 answers
  1. Sternico
    Sternico avatar
    25 posts
    Member since:
    Sep 2009

    Posted 11 Jul 2011 Link to this post

    Hello,

    I have a custom control which inherits from usercontrol. My control is the itemtemplate of a radtreeview.

    <telerik:RadTreeView.ItemTemplate>

        <HierarchicalDataTemplate ItemsSource="{Binding MyList}">

             <MyControls:MyTreeNode AllowDrop="{Binding IsDropAllowed}"/>

        </HierarchicalDataTemplate>

    </telerik:RadTreeView.ItemTemplate>

     

    I want to bind the AllowDrop Property from my control (MyTreeNode). When AllowDrop is false, it should not possible to drop other nodes on this node. But this doesn’t work. The radtreeview ignores the allocation. Is there any way that my control has the same behavior likes a radtreeviewitem, when the IsDropAllowed Property is false.


    With best regards,
    Sico

  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 14 Jul 2011 Link to this post

    Hello Sternico,

    You cannot bind a property of a CustomControl inside Template to a Property of the Container(the owner of the template) in this way. However, I guess you need to disable the Drop over the whole RadTreeViewItem. Then, supposing your is bound to ObservableCollection<> of DataItems, you can introduce AllowDrop property in the DataItem class too. then you have to bind the IsDropAllowed property of the RadTreeViewItem to the AllowDrop property of the business object via StyleBindings like so:
    <Style TargetType="telerik:RadTreeViewItem">
         <Setter Property="IsDropAllowed" Value="{Binding AllowDrop}" />
    Please elaborate more on your scenario if you need something different. Thank you you for your cooperation.

    Regards,
    Petar Mladenov
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. UI for WPF is Visual Studio 2017 Ready
  4. Sternico
    Sternico avatar
    25 posts
    Member since:
    Sep 2009

    Posted 15 Jul 2011 Link to this post

    Thank you this was very helpful!
    I still have
    one final question. This works for every node include the root node. But it’s still possible to drop an element before or after the root node. How can I stop this?

  5. Sternico
    Sternico avatar
    25 posts
    Member since:
    Sep 2009

    Posted 20 Jul 2011 Link to this post

    Today I used the new telerik controls (Q2 2011). Since the 'IsDropAllowed' Property is ignored. I set the Property to true, but isn't allowed to drop on the node! With Q1 2011 it works fine!
  6. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 20 Jul 2011 Link to this post

    Hello Sternico,

     I was unable to reproduce your issue using the Official Q2 2011 dlls. Could you please examine my test project and let me know if I have missed something? You can modify it so that it demonstrates the problem. Thank you in advance for your cooperation.

    All the best,
    Petar Mladenov
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  7. Sahi
    Sahi avatar
    2 posts
    Member since:
    Apr 2015

    Posted 20 Apr 2015 Link to this post

    I have hierarchical structure observable collection of documents which contains a collections of Pages and a Page can contain a collection of Controls.

    Which i have bind to radtreeview:

     <telerik:RadTreeView IsDragPreviewEnabled="True" IsDragDropEnabled="True" x:Name="tvDocBWR" ItemsSource="{Binding IsAsync=True, Source={x:Static s:Global.DocumentBrowserObjects}}">
                            <telerik:RadTreeView.ItemContainerStyle>
                                <Style TargetType="{x:Type telerik:RadTreeViewItem}">
                                    <Setter Property="Visibility">
                                        <Setter.Value>
                                            <MultiBinding ConverterParameter="ShowActiveDoc"   Converter="{StaticResource BoolToVisibiltyCon}">
                                                <Binding Path="DataContext.ShowActiveDocument" RelativeSource="{RelativeSource Mode=FindAncestor,AncestorType=UserControl}"></Binding>
                                                <Binding Path="IsActive" ></Binding>
                                            </MultiBinding>
                                        </Setter.Value>
                                    </Setter>
                                    <Setter Property="IsDropAllowed">
                                        <Setter.Value>
                                            <Binding Path="." Converter="{StaticResource AllowDropCon}"></Binding>
                                        </Setter.Value>
                                    </Setter>
                                  
                                    <!--<EventSetter Event="TreeViewItem.DragLeave" Handler="TvDocBWR_DragLeave"/>
                                    <EventSetter Event="TreeViewItem.DragOver" Handler="TvDocBWR_DragOver"/>
                                    <EventSetter Event="TreeViewItem.Drop" Handler="TvDocBWR_Drop"/>
                                    <EventSetter Event="TreeViewItem.MouseMove" Handler="TvDocBWR_MouseMove"/>-->
                                </Style>
                            </telerik:RadTreeView.ItemContainerStyle>
                            <telerik:RadTreeView.ItemTemplate>
                                    <HierarchicalDataTemplate DataType="{x:Type designer:Page}"  ItemsSource="{Binding  Pages}" >
                                        <HierarchicalDataTemplate.Triggers>
                                            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=IsExpanded}" Value="True">
                                                <Setter TargetName="DocBWRimg" Property="Image.Source"  Value="{Binding Source={x:Static resx:Resources1.DOCS_BRWS_Doc_Expanded}}"/>
                                            </DataTrigger>
                                        </HierarchicalDataTemplate.Triggers>
                                        <StackPanel Orientation="Horizontal">
                                            <Image Name="DocBWRimg"  RenderOptions.BitmapScalingMode="NearestNeighbor" RenderOptions.EdgeMode="Aliased"  Source="{Binding Source={x:Static resx:Resources1.DOCS_BRWS_Doc}}"></Image>
                                            <TextBlock  Margin="3,0,0,0"  Uid="{Binding DocumentID}" Text="{Binding DocumentHeaderText}" >
                                            </TextBlock>
                                        </StackPanel>
                                        <HierarchicalDataTemplate.ItemTemplate>

                                            <HierarchicalDataTemplate  ItemsSource="{Binding Controls, IsAsync=True}">
                                                <StackPanel Orientation="Horizontal">
                                                    <Image RenderOptions.BitmapScalingMode="NearestNeighbor" RenderOptions.EdgeMode="Aliased" Source="{Binding Source={x:Static resx:Resources1.DOCS_BRWS_Page} }"></Image>
                                                    <TextBlock Margin="3,0,0,0"  Text="{Binding Name}" />
                                                </StackPanel>

                                                <HierarchicalDataTemplate.ItemTemplate>
                                                    <DataTemplate>
                                                        <StackPanel Orientation="Horizontal">
                                                            <Image  RenderOptions.BitmapScalingMode="NearestNeighbor" RenderOptions.EdgeMode="Aliased"    Source="{Binding Tag}"></Image>
                                                            <TextBlock Margin="3,0,0,0" Text="{Binding Name}" />

                                                        </StackPanel>
                                                    </DataTemplate>

                                                </HierarchicalDataTemplate.ItemTemplate>

                                            </HierarchicalDataTemplate>
                                        </HierarchicalDataTemplate.ItemTemplate>

                                    </HierarchicalDataTemplate>
                            </telerik:RadTreeView.ItemTemplate>
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="SelectedItemChanged">
                                    <cmd:EventToCommand  PassEventArgsToCommand="True"  Command="{Binding TVSelectionChangedCommand}" />
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </telerik:RadTreeView>

    in the style where target type is Radtreeview item i wrote a converter to set isDropallowed property and passing context to its converter by Path="." Converter code is following

     public class DroppableZoneConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                if (value is FormDesigner.DesignerControls.Document)
                    return false;
                else if (value is FormDesigner.DesignerControls.Page)
                    return false;
                else
                    return true;
            }

            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
                throw new NotImplementedException();
            }
        }

     

    But its now happening. Please suggest how i can set IsDropAllowed property of each treeviewitem

  8. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 21 Apr 2015 Link to this post

    Hello Sahi,

    I am not sure whether your Converter does not fire  /  does not provide the correct arguments or whether the property IsDropAllowed does not work correctly. Please check my test project in which the Covnerter fires successfully, the *value* in it provides the business object RadTreeViewIten is bound to. Also, the converter returns false (only for testing purpose) and indeed, no drop can be performed inside RadTreeViewItems.

    Regards,
    Petar Mladenov
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top
UI for WPF is Visual Studio 2017 Ready