I have a treeview and a gridview. The user should be able to move elements from the gridview to the treeview and change the effect of the drag&drop action by using the shift or control key (like in Windows Explorer).
In the GiveFeedback event the effect is set according to the pressed key and also the visualization shows the expected behavior. But in the Drop event (on the treeview) and in the DragDropCompleted event (on the gridview) the effect is set to All, therefore I'm not able to decide if I have to remove the Element from the current list.
Am I missing something or is there a Bug in the library?
XAML:
<Window x:Class="DragAndDropToTreeView.MainWindow" xmlns:local="clr-namespace:DragAndDropToTreeView" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" Title="MainWindow" Width="623" Height="461"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="1*" /> <ColumnDefinition Width="2*" /> </Grid.ColumnDefinitions> <telerik:RadTreeView AllowDrop="True" ItemsSource="{Binding Folders}" SelectedItem="{Binding SelectedFolder, Mode=TwoWay}" SelectionMode="Single"> <telerik:RadTreeView.Resources> <HierarchicalDataTemplate DataType="{x:Type local:Folder}" ItemsSource="{Binding Children}"> <Grid VerticalAlignment="Center"> <TextBlock VerticalAlignment="Center" Text="{Binding Name}" local:TreeItemDropBehavior.IsEnabled="True" /> </Grid> </HierarchicalDataTemplate> </telerik:RadTreeView.Resources> </telerik:RadTreeView> <telerik:RadGridView Grid.Column="1" AllowDrop="True" AutoGenerateColumns="False" CanUserFreezeColumns="False" CanUserReorderColumns="False" CanUserResizeColumns="False" FontSize="12" IsFilteringAllowed="False" IsReadOnly="True" ItemsSource="{Binding SelectedFolder.Elements}" RowHeight="32" RowIndicatorVisibility="Collapsed" SelectionMode="Multiple" ShowGroupPanel="False" local:GridViewDragDropBehavior.IsEnabled="True" telerik:DragDropManager.AllowCapturedDrag="True" telerik:DragDropManager.AllowDrag="True"> <telerik:RadGridView.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary> <DataTemplate x:Key="DraggedItemTemplate"> <StackPanel Orientation="Horizontal"> <TextBlock Text="Dragging: " /> <TextBlock FontWeight="Bold" Text="{Binding CurrentDraggedItems.Count}" /> <TextBlock Text=" Element(s)" /> </StackPanel> </DataTemplate> </ResourceDictionary> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </telerik:RadGridView.Resources> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn Width="100" DataMemberBinding="{Binding Name}" Header="Name" /> <telerik:GridViewDataColumn Width="250" DataMemberBinding="{Binding Description}" Header="Description" /> </telerik:RadGridView.Columns> </telerik:RadGridView> </Grid></Window>
GridViewDragDropBehavior.cs:
using System.Collections;using System.Collections.Generic;using System.Diagnostics;using System.Windows;using System.Windows.Input;using Telerik.Windows.Controls;using Telerik.Windows.DragDrop;using Telerik.Windows.DragDrop.Behaviors;using GiveFeedbackEventArgs = Telerik.Windows.DragDrop.GiveFeedbackEventArgs;namespace DragAndDropToTreeView{ public class GridViewDragDropBehavior { public RadGridView AssociatedControl { get; set; } private static readonly Dictionary<RadGridView, GridViewDragDropBehavior> Instances; static GridViewDragDropBehavior() { Instances = new Dictionary<RadGridView, GridViewDragDropBehavior>(); } public static bool GetIsEnabled(DependencyObject obj) { return (bool)obj.GetValue(IsEnabledProperty); } public static void SetIsEnabled(DependencyObject obj, bool value) { GridViewDragDropBehavior behavior = GetAttachedBehavior(obj as RadGridView); behavior.AssociatedControl = obj as RadGridView; if (value) { behavior.Initialize(); } else { behavior.CleanUp(); } obj.SetValue(IsEnabledProperty, value); } public static readonly DependencyProperty IsEnabledProperty = DependencyProperty.RegisterAttached( "IsEnabled", typeof(bool), typeof(GridViewDragDropBehavior), new PropertyMetadata(OnIsEnabledPropertyChanged)); public static void OnIsEnabledPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { SetIsEnabled(dependencyObject, (bool)e.NewValue); } private static GridViewDragDropBehavior GetAttachedBehavior(RadGridView gridView) { if (!Instances.ContainsKey(gridView)) { Instances[gridView] = new GridViewDragDropBehavior { AssociatedControl = gridView }; } return Instances[gridView]; } protected virtual void Initialize() { UnsubscribeFromDragDropEvents(); SubscribeToDragDropEvents(); } protected virtual void CleanUp() { UnsubscribeFromDragDropEvents(); } private void SubscribeToDragDropEvents() { DragDropManager.AddDragInitializeHandler(AssociatedControl, OnDragInitialize); DragDropManager.AddGiveFeedbackHandler(AssociatedControl, OnGiveFeedback); DragDropManager.AddDragDropCompletedHandler(AssociatedControl, OnDragDropCompleted); DragDropManager.AddDragOverHandler(AssociatedControl, OnDragOver); } private void UnsubscribeFromDragDropEvents() { DragDropManager.RemoveDragInitializeHandler(AssociatedControl, OnDragInitialize); DragDropManager.RemoveGiveFeedbackHandler(AssociatedControl, OnGiveFeedback); DragDropManager.RemoveDragDropCompletedHandler(AssociatedControl, OnDragDropCompleted); DragDropManager.RemoveDragOverHandler(AssociatedControl, OnDragOver); } private void OnDragInitialize(object sender, DragInitializeEventArgs e) { DropIndicationDetails details = new DropIndicationDetails(); var gridView = sender as RadGridView; details.DragSource = gridView.ItemsSource; var items = gridView.SelectedItems; details.CurrentDraggedItems = items; IDragPayload dragPayload = DragDropPayloadManager.GeneratePayload(null); dragPayload.SetData("DraggedData", items); dragPayload.SetData("DropDetails", details); e.Data = dragPayload; e.DragVisual = new DragVisual { Content = details, ContentTemplate = AssociatedControl.Resources["DraggedItemTemplate"] as DataTemplate }; e.DragVisualOffset = new Point(e.RelativeStartPoint.X + 10, e.RelativeStartPoint.Y); e.AllowedEffects = DragDropEffects.All; } private void OnGiveFeedback(object sender, GiveFeedbackEventArgs e) { Debug.WriteLine("GridViewDragDropBehavior.OnGiveFeedback {0}", e.Effects); e.SetCursor(Cursors.Arrow); e.Handled = true; } private void OnDragDropCompleted(object sender, DragDropCompletedEventArgs e) { Debug.WriteLine("GridViewDragDropBehavior.OnDragDropCompleted: {0}", e.Effects); var data = DragDropPayloadManager.GetDataFromObject(e.Data, "DraggedData") as IList; var details = DragDropPayloadManager.GetDataFromObject(e.Data, "DropDetails"); Debug.WriteLine(e.Effects); // Remove Element from source list if drag drop effect is move /*if (e.Effects == DragDropEffects.Move) { var collection = (details as DropIndicationDetails).DragSource as IList; foreach(var element in data) { collection.Remove(element); } }*/ } private void OnDragOver(object sender, Telerik.Windows.DragDrop.DragEventArgs e) { Debug.WriteLine("GridViewDragDropBehavior.OnDragOver: {0}", e.Effects); e.Effects = DragDropEffects.None; e.Handled = true; } }}
TreeItemDropBehavior.cs:
using System.Collections;using System.Collections.Generic;using System.Diagnostics;using System.Windows;using System.Windows.Input;using Telerik.Windows.Controls;using Telerik.Windows.DragDrop;namespace DragAndDropToTreeView{ public class TreeItemDropBehavior { /// <summary> /// AssociatedObject Property /// </summary> public RadTreeViewItem AssociatedObject { get; set; } private static readonly Dictionary<RadTreeViewItem, TreeItemDropBehavior> Instances; static TreeItemDropBehavior() { Instances = new Dictionary<RadTreeViewItem, TreeItemDropBehavior>(); } public static bool GetIsEnabled(DependencyObject obj) { return (bool)obj.GetValue(IsEnabledProperty); } public static void SetIsEnabled(DependencyObject obj, bool value) { var treeViewItem = obj.ParentOfType<RadTreeViewItem>(); TreeItemDropBehavior behavior = GetAttachedBehavior(treeViewItem); behavior.AssociatedObject = treeViewItem; if (value) { behavior.Initialize(); } else { behavior.CleanUp(); } obj.SetValue(IsEnabledProperty, value); } // Using a DependencyProperty as the backing store for IsEnabled. This enables animation, styling, binding, etc... public static readonly DependencyProperty IsEnabledProperty = DependencyProperty.RegisterAttached( "IsEnabled", typeof(bool), typeof(TreeItemDropBehavior), new PropertyMetadata(OnIsEnabledPropertyChanged)); public static void OnIsEnabledPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { SetIsEnabled(dependencyObject, (bool)e.NewValue); } private static TreeItemDropBehavior GetAttachedBehavior(RadTreeViewItem treeViewItem) { if (!Instances.ContainsKey(treeViewItem)) { Instances[treeViewItem] = new TreeItemDropBehavior { AssociatedObject = treeViewItem }; } return Instances[treeViewItem]; } protected virtual void Initialize() { DragDropManager.AddGiveFeedbackHandler(AssociatedObject, OnGiveFeedback); DragDropManager.AddDropHandler(AssociatedObject, OnDrop); } protected virtual void CleanUp() { DragDropManager.RemoveGiveFeedbackHandler(AssociatedObject, OnGiveFeedback); DragDropManager.RemoveDropHandler(AssociatedObject, OnDrop); } private void OnGiveFeedback(object sender, Telerik.Windows.DragDrop.GiveFeedbackEventArgs e) { Debug.WriteLine("TreeItemDropBehavior.OnGiveFeedback {0}", e.Effects); e.SetCursor(Cursors.Arrow); e.Handled = true; } private void OnDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs e) { Debug.WriteLine("TreeItemDropBehavior.OnDrop: {0}", e.Effects); if (e.Effects != DragDropEffects.None) { var destinationItem = (e.OriginalSource as FrameworkElement).ParentOfType<RadTreeViewItem>(); var data = DragDropPayloadManager.GetDataFromObject(e.Data, "DraggedData") as IList; var details = DragDropPayloadManager.GetDataFromObject(e.Data, "DropDetails") as DropIndicationDetails; if (destinationItem != null) { foreach (var element in data) { (destinationItem.DataContext as Folder).Elements.Add(element as Element); } e.Handled = true; } } } }}
I thought I would try using the new Material theme with a new WPF project.
All good but for some reason there is no filtering available in the RadGridViews in my project.
As soon as I change to one of the older themes the filtering comes back, When I change back to Material Theme it disappears.
Any help greatly appreciated.
Hi @ all,
we are thinking to create a small Barcode-Designer with telerik wpf Controls. Conditions:
- Creating Layouts in different dimensions.
- Load Layout out of (txt) File and
- Add Fields like text, Real/Integer, Images, Barcodes
- Save the Layout in a file (.txt?) like:
- Print a Testfile in pdf.
Second Programm running on a windows client
Which controls are usefull? Is it possible to do with telerik wpf controls?
Any Ideas?
Thanks a lot
Best Regards
RENE
Hi,
I would like to know, if it is possible to fit to a type of "box"-Coordinates inside the PDF-Files
I would like to open a pdf and then define the "View" to display.
Could be 4 Points (Left upper/Right upper/Right lower/Left lower) or (Left upper + Width/Height) or something similiar.
Then the PDF-Viewer should scroll to the left upper point and zoom to have the "box" displayed.
Is this possible?
Thanks
Juergen


Hello,
I have a RadcomboBox with Multiple Selection allowed. The ItemSource of this combo is a enum.
public enum WorkStatus {
[Description("WORKING")]
Working,
[Description("NOT WORKING")]
Not_Working,
[Description("WORKING WITH ERRORS")]
Working_with_errors,
[Description("STOPPED")]
Stopped
}
And this is my code:
<Window x:Class="MultiSelectComboboxEnums.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:local="clr-namespace:MultiSelectComboboxEnums"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="MainWindow"
Height="350"
Width="525">
<Window.Resources>
<ObjectDataProvider x:Key="statesWork"
MethodName="GetValues"
ObjectType="{x:Type sys:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="local:WorkStatus" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<local:EnumToFriendlyNameConverter x:Key="enumToFriendlyNameConverter" />
</Window.Resources>
<Grid>
<telerik:RadComboBox Width="350"
Height="26"
Margin="20"
HorizontalAlignment="Center"
VerticalAlignment="Center"
telerik:StyleManager.Theme="Windows8"
ItemsSource="{Binding Source={StaticResource statesWork}}"
ClearSelectionButtonVisibility="Visible"
IsSynchronizedWithCurrentItem="False"
AllowMultipleSelection="True"
MultipleSelectionSeparator="|"
MultipleSelectionSeparatorStringFormat="{} {0} ">
<telerik:RadComboBox.ItemTemplate>
<DataTemplate>
<Label Height="Auto"
Margin="0"
VerticalAlignment="Center"
Content="{Binding Path=., Mode=OneWay, Converter={StaticResource enumToFriendlyNameConverter}}" />
</DataTemplate>
</telerik:RadComboBox.ItemTemplate>
</telerik:RadComboBox>
</Grid>
</Window>
In dropdown item I can see the correct name using a converter but how can I do to see the same in the selected items box?
I attached two images showing this error.
Thanks in advance.
Hi.
I'm considering the purchase of UI for WPF, so I downloaded to test the trial version.
I'm working through this example (http://docs.telerik.com/devtools/wpf/controls/raddataservicedatasource/getting-started/creating-the-data-bound-controls), but instead of WCF services, I'm using OData version 7.
Everything works fine, except when I'm trying to apply even a single filter on columns containing enum elements, I'm getting this exception :
Babken Gevorgyan, [01.08.17 13:36]
System.Windows.Data Error: 8 : Cannot save value from target back to source. BindingExpression:Path=IsActive; DataItem='DistinctValueViewModel' (HashCode=2921675); target element is 'CheckBox' (Name=''); target property is 'IsChecked' (type 'Nullable`1') NotSupportedException:'System.NotSupportedException: Could not convert constant Credit expression to string.
at Microsoft.OData.Client.ExpressionWriter.VisitConstant(ConstantExpression c)
at Microsoft.OData.Client.ALinqExpressionVisitor.Visit(Expression exp)
at Microsoft.OData.Client.DataServiceALinqExpressionVisitor.Visit(Expression exp)
at Microsoft.OData.Client.ExpressionWriter.Visit(Expression exp)
at Microsoft.OData.Client.ExpressionWriter.VisitOperand(Expression e, Nullable`1 parentType, Nullable`1 childDirection)
at Microsoft.OData.Client.ExpressionWriter.VisitBinary(BinaryExpression b)
at Microsoft.OData.Client.ALinqExpressionVisitor.Visit(Expression exp)
at Microsoft.OData.Client.DataServiceALinqExpressionVisitor.Visit(Expression exp)
at Microsoft.OData.Client.ExpressionWriter.Visit(Expression exp)
at Microsoft.OData.Client.ExpressionWriter.ExpressionToString(DataServiceContext context, Expression e, Boolean inPath, Version& uriVersion)
at Microsoft.OData.Client.UriWriter.VisitQueryOptionExpression(FilterQueryOptionExpression fqoe)
at Microsoft.OData.Client.UriWriter.VisitQueryOptions(ResourceExpression re)
at Microsoft.OData.Client.UriWriter.VisitQueryableResourceExpression(QueryableResourceExpression rse)
at Microsoft.OData.Client.DataServiceALinqExpressionVisitor.Visit(Expression exp)
at Microsoft.OData.Client.UriWriter.Translate(DataServiceContext context, Boolean addTrailingParens, Expression e, Uri& uri, Version& version)
at Microsoft.OData.Client.DataServiceQueryProvider.Translate(Expression e)
at Microsoft.OData.Client.DataServiceQuery`1.get_RequestUri()
at Telerik.Windows.Data.QueryableDataServiceCollectionView`1.ReturnsSingleEntity(DataServiceQuery`1 query)
at Telerik.Windows.Data.QueryableDataServiceCollectionView`1.BuildDataServiceQuery(Int32 pageIndex)
at Telerik.Windows.Controls.DataServices.QueryableDataServiceCollectionViewBase.CompletePageMove(Int32 newPageIndex)
at Telerik.Windows.Data.QueryableCollectionView.MoveToPageCore(Int32 index)
at Telerik.Windows.Controls.DataServices.QueryableDataServiceCollectionViewBase.MoveToPageCore(Int32 index)
at Telerik.Windows.Data.QueryableCollectionView.InvalidatePaging()
at Telerik.Windows.Data.QueryableCollectionView.InvalidatePagingAndRefresh()
at Telerik.Windows.Data.QueryableCollectionView.OnFilterDescriptorsChanged()
at Telerik.Windows.Data.QueryableDataServiceCollectionView`1.OnFilterDescriptorsCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at Telerik.Windows.Data.RadObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at Telerik.Windows.Data.ObservableItemCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
at Telerik.Windows.Data.RadObservableCollection`1.InsertItem(Int32 index, T item)
at Telerik.Windows.Data.FilterDescriptorCollection.InsertItem(Int32 index, IFilterDescriptor item)
at System.Collections.ObjectModel.Collection`1.Insert(Int32 index, T item)
at System.Collections.ObjectModel.Collection`1.System.Collections.IList.Insert(Int32 index, Object value)
at Telerik.Windows.Data.CollectionHelper.Insert(IList target, IEnumerable newItems, Int32 startingIndex, IEqualityComparer itemComparer)
at Telerik.Windows.Data.ObservableCollectionManager.HandleCollectionChanged(IList sender, NotifyCollectionChangedEventArgs args)
Babken Gevorgyan, [01.08.17 13:36]
at Telerik.Windows.Data.ObservableCollectionManager.Telerik.Windows.Data.IWeakEventListener<System.Collections.Specialized.NotifyCollectionChangedEventArgs>.ReceiveWeakEvent(Object sender, NotifyCollectionChangedEventArgs args)
at Telerik.Windows.Data.WeakEvent.WeakListener`1.Handler(Object sender, TArgs args)
at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at Telerik.Windows.Data.RadObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at Telerik.Windows.Data.ObservableItemCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
at Telerik.Windows.Data.RadObservableCollection`1.InsertItem(Int32 index, T item)
at Telerik.Windows.Data.FilterDescriptorCollection.InsertItem(Int32 index, IFilterDescriptor item)
at System.Collections.ObjectModel.Collection`1.Add(T item)
at Telerik.Windows.Controls.GridViewColumn.OnColumnFilterDescriptorPropertyChanged(Object sender, PropertyChangedEventArgs e)
at Telerik.Windows.Data.DescriptorBase.OnPropertyChanged(PropertyChangedEventArgs args)
at Telerik.Windows.Data.DescriptorBase.OnPropertyChanged(String propertyName)
at Telerik.Windows.Data.DescriptorBase.ResumeNotifications()
at Telerik.Windows.Controls.GridView.FilteringViewModel.ApplyFilters()
at Telerik.Windows.Controls.GridView.FilteringViewModel.OnDistinctValuesChanged()
at Telerik.Windows.Controls.GridView.FilteringViewModel.OnDistinctValuesItemChanged(Object sender, ItemChangedEventArgs`1 e)
at Telerik.Windows.Data.ObservableItemCollection`1.RaiseGenericItemChanged(ItemChangedEventArgs`1 e)
at Telerik.Windows.Data.ObservableItemCollection`1.OnItemChanged(ItemChangedEventArgs`1 e)
at Telerik.Windows.Data.ObservableItemCollection`1.Telerik.Windows.Data.IWeakEventListener<System.ComponentModel.PropertyChangedEventArgs>.ReceiveWeakEvent(Object sender, PropertyChangedEventArgs args)
at Telerik.Windows.Data.WeakEvent.WeakListener`1.Handler(Object sender, TArgs args)
at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)
at Telerik.Windows.Controls.ViewModelBase.OnPropertyChanged(String propertyName)
at Telerik.Windows.Controls.GridView.DistinctValueViewModel.set_IsActive(Boolean value)'
Thanks.
Hi,
I need to attach my project how should i attach it was a .Zip file.
I am having an issue in RadTabItem with ContentControl which hides the DockPanel.
If you run the attached project you may see the PresetTitle Dockpanel in the right hand side of the window and mouse over to the PresetTitle Content(Don't pin the dock panel)you may see 3 Tab's underneath(Preset,group,SiteSee) that and select all the 3 Tab's one by one continuously for 3 or more times and it automatically hide the PresetTitle dockpanel that should not happen.
If i have not use the ContentControl it works fine.
Please check in the project that Goto TestUserControl.xaml uncomment the line from 32 to 37 and comment the line 38 and run the application it is working as expected.
My scenario is i need to use the contentControl inside the Tab Control.
Please check and let me know what i am doing wrong.
Thanks In Advance :)
Regards,
P.Sathish Kumar
I have a Telerik Treeview on a Telerik Docking RadPane. If the pane is unpinned, so the user no longer can see the tree, a call to GetItemByPath returns null.
I give the user an option to pin the pane, and navigate the tree, or unpin the pane, and click "Next" and "Previous" buttons to navigate the tree. If the pane is pinned and the tree is visible, GetItemByPath returns the RadTreeViewItem. If the tree is hidden, GetItemByPath returns null.
If I expand all nodes on the tree first, GetItemByPath returns the RadTreeViewItem even when the tree is hidden. I have IsVirtualizing set to false.
Is there a way to set the SelectedItem using GetItemByPath when the tree is not visible? Or is there another call I can make?
Thanks,
Scott