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
6 Answers, 1 is accepted
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}" />
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!
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?
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!
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
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.