Telerik Forums
UI for WPF Forum
7 answers
225 views
Hi All,

  i have a requirement to implement d&d functionality for radgridview(only drag) to textBox (only drop) control.so i tried the drag and drop demo application comes with the telerik suite. gridview to listbox is working fine and the problem is don't know how to implement for textbox control and textbox value should be either one of the dragging column of gridview in MVVM pattern.

   
<UserControl x:Class="TelerikDragandDrop.MainWindow"
        xmlns:telerikDragandDrop="clr-namespace:TelerikDragandDrop">
 
    <UserControl.Resources>
        <telerikDragandDrop:MainViewModel x:Key="ViewModel"/>
 
         
        <!--Note: With this style we make the ListBoxItems draggable:-->
        <Style TargetType="ListBoxItem" x:Key="WishlistItemStyle" >
            <Setter Property="telerik:DragDropManager.AllowCapturedDrag" Value="True" />
            <Setter Property="telerik:DragDropManager.TouchDragTrigger" Value="TapAndHold"/>
        </Style>
        <Style TargetType="telerik:GridViewRow" x:Key="OrderItemStyle" >
            <Setter Property="telerik:DragDropManager.AllowCapturedDrag" Value="True" />
            <Setter Property="telerik:DragDropManager.TouchDragTrigger" Value="TapAndHold"/>
        </Style>
 
        <Style TargetType="{x:Type TextBox}" x:Key="textBoxStyle">
            <Setter Property="telerik:DragDropManager.AllowCapturedDrag" Value="False" />
            <Setter Property="telerik:DragDropManager.TouchDragTrigger" Value="TapAndHold"/>
            <Setter Property="Foreground" Value="#777777" />
        </Style>
         
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
 
        
 
        <!--Order-->
        <Border BorderBrush="#C8C9CC" BorderThickness="2" CornerRadius="6" Margin="46 46 0 46"
                Background="White" Grid.Column="1">
            <DockPanel>
                <Border DockPanel.Dock="Top"
                        Background="{telerik:Windows8Resource ResourceKey=AccentBrush}" CornerRadius="4 4 0 0">
                    <TextBlock Text="Order" Foreground="{telerik:Windows8Resource ResourceKey=MainBrush}" Margin="20 5 5 5" FontSize="14" />
                </Border>
                <!--NOTE: The GridView is a drop target, we set the AllowDrop to true.-->
                <telerik:RadGridView x:Name="orderView" IsReadOnly="True" Grid.Column="1" Grid.Row="0" Margin="0,0,0,5"
                                     RowIndicatorVisibility="Collapsed" GroupRenderMode="Flat" ItemsSource="{Binding AllApplications, Source={StaticResource ViewModel}}"
                                     RowStyle="{StaticResource OrderItemStyle}" CanUserFreezeColumns=" False" CanUserInsertRows="False"
                                     CanUserReorderColumns="False" CanUserSortColumns="False" ShowGroupPanel="False" Padding="5" AllowDrop="True"
                                     telerikDragandDrop:GridViewDragDropBehavior.IsEnabled="True" Height="115">
                    <telerik:RadGridView.Resources>
                         
                        <DataTemplate x:Key="DraggedItemTemplate">
                            <StackPanel>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="Dragging:"/>
                                    <TextBlock Text="{Binding CurrentDraggedItem.FirstName}" FontWeight="Bold"/>
                                </StackPanel>
                                 
                            </StackPanel>
                        </DataTemplate>
                    </telerik:RadGridView.Resources>
                </telerik:RadGridView>
            </DockPanel>
        </Border>
 
        <!--Whishlist-->
        <Border BorderBrush="#C8C9CC" BorderThickness="2" CornerRadius="6" Margin="46"
                Background="White" Grid.Column="2">
            <DockPanel>
                <Border DockPanel.Dock="Top"
                        Background="{telerik:Windows8Resource ResourceKey=AccentBrush}" CornerRadius="4 4 0 0">
                    <TextBlock Text="Wishlist" Margin="20 5 5 5" Foreground="{telerik:Windows8Resource ResourceKey=MainBrush}" FontSize="14" />
                </Border>
                <!--NOTE: The ListBox is a drop target, we set the AllowDrop to true.-->
                <ListBox x:Name="wishlistView" Grid.Column="1" Grid.Row="1"
                         SelectionMode="Extended"
                         ItemsSource="{Binding MyApplications, Source={StaticResource ViewModel}}" FontSize="11"
                      
                         ItemContainerStyle="{StaticResource WishlistItemStyle}" Padding="5" AllowDrop="True"
                         telerikDragandDrop:ListBoxDragDropBehavior.IsEnabled="True"
                         telerik:TouchManager.IsTouchHitTestVisible="True">
                    <ListBox.Resources>
                       
                        <DataTemplate x:Key="DraggedItemTemplate">
                            <StackPanel>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="Dragging:"/>
                                    <TextBlock Text="{Binding CurrentDraggedItem.FirstName}" FontWeight="Bold"/>
                                </StackPanel>
                               
                            </StackPanel>
                             
                        </DataTemplate>
                    </ListBox.Resources>
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Grid Width="150">
                                <Grid.RowDefinitions>
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                </Grid.RowDefinitions>
                               <TextBlock Grid.Row="1" Text="{Binding FirstName}" FontWeight="Bold"
                                   HorizontalAlignment="Center" Foreground="#FF767676"/>
                                <TextBlock Text="{Binding LastName}" Grid.Row="2"
                                   HorizontalAlignment="Center" Foreground="#FF767676"/>
                            </Grid>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </DockPanel>
        </Border>
        <TextBox Height="35" Name="TextBox1" Style="{StaticResource textBoxStyle}"  AllowDrop="True"   Width="225" Grid.Column="2" Margin="24,204,13,8"   telerikDragandDrop:TextBoxDragDropBehaviour.IsEnabled="True"  telerik:TouchManager.IsTouchHitTestVisible="True" />
    </Grid>
</UserControl>
public class TextBoxDragDropBehaviour
   {
       private TextBox _associatedObject;
 
       /// <summary>
       /// AssociatedObject Property
       /// </summary>
       public TextBox AssociatedObject
       {
           get
           {
               return _associatedObject;
           }
           set
           {
               _associatedObject = value;
           }
       }
 
       private static Dictionary<TextBox, TextBoxDragDropBehaviour> instances;
 
       static TextBoxDragDropBehaviour()
       {
           instances = new Dictionary<TextBox, TextBoxDragDropBehaviour>();
       }
 
       public static bool GetIsEnabled(DependencyObject obj)
       {
           return (bool)obj.GetValue(IsEnabledProperty);
       }
 
       public static void SetIsEnabled(DependencyObject obj, bool value)
       {
           TextBoxDragDropBehaviour behavior = GetAttachedBehavior(obj as TextBox );
 
           behavior.AssociatedObject = obj as TextBox;
 
           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(TextBoxDragDropBehaviour),
               new PropertyMetadata(new PropertyChangedCallback(OnIsEnabledPropertyChanged)));
       public static void OnIsEnabledPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
       {
           SetIsEnabled(dependencyObject, (bool)e.NewValue);
       }
 
       private static TextBoxDragDropBehaviour GetAttachedBehavior(TextBox listBox)
       {
           if (!instances.ContainsKey(listBox))
           {
               instances[listBox] = new TextBoxDragDropBehaviour();
               instances[listBox].AssociatedObject = listBox;
           }
 
           return instances[listBox];
       }
 
       protected virtual void Initialize()
       {
           this.UnsubscribeFromDragDropEvents();
           this.SubscribeToDragDropEvents();
       }
 
       protected virtual void CleanUp()
       {
           this.UnsubscribeFromDragDropEvents();
       }
 
       private void SubscribeToDragDropEvents()
       {
           DragDropManager.AddDragInitializeHandler(this.AssociatedObject, OnDragInitialize);
           DragDropManager.AddGiveFeedbackHandler(this.AssociatedObject, OnGiveFeedback);
           DragDropManager.AddDropHandler(this.AssociatedObject, OnDrop);
           DragDropManager.AddDragDropCompletedHandler(this.AssociatedObject, OnDragDropCompleted);
           DragDropManager.AddDragOverHandler(this.AssociatedObject, OnDragOver);
       }
 
       private void UnsubscribeFromDragDropEvents()
       {
           DragDropManager.RemoveDragInitializeHandler(this.AssociatedObject, OnDragInitialize);
           DragDropManager.RemoveGiveFeedbackHandler(this.AssociatedObject, OnGiveFeedback);
           DragDropManager.RemoveDropHandler(this.AssociatedObject, OnDrop);
           DragDropManager.RemoveDragDropCompletedHandler(this.AssociatedObject, OnDragDropCompleted);
           DragDropManager.RemoveDragOverHandler(this.AssociatedObject, OnDragOver);
       }
 
       private void OnDragInitialize(object sender, DragInitializeEventArgs e)
       {
           DropIndicationDetails details = new DropIndicationDetails();
           var listBoxItem = e.OriginalSource as System.Windows.Controls.ListBoxItem ?? (e.OriginalSource as FrameworkElement).ParentOfType<System.Windows.Controls.ListBoxItem>();
 
           var textBox = sender as System.Windows.Controls.TextBox;
           if (textBox != null)
           {
               var item = listBoxItem != null ? listBoxItem.DataContext : textBox.Text;
               details.CurrentDraggedItem = item;
 
               IDragPayload dragPayload = DragDropPayloadManager.GeneratePayload(null);
 
               dragPayload.SetData("DraggedData", item);
               dragPayload.SetData("DropDetails", details);
 
               e.Data = dragPayload;
           }
 
           e.DragVisual = new DragVisual()
           {
               Content = details,
               ContentTemplate = this.AssociatedObject.Resources["DraggedItemTemplate"] as DataTemplate
           };
           e.DragVisualOffset = e.RelativeStartPoint;
           e.AllowedEffects = DragDropEffects.All;
       }
 
       private void OnGiveFeedback(object sender, Telerik.Windows.DragDrop.GiveFeedbackEventArgs e)
       {
           e.SetCursor(Cursors.Arrow);
           e.Handled = true;
       }
 
       private void OnDragDropCompleted(object sender, DragDropCompletedEventArgs e)
       {
           var draggedItem = DragDropPayloadManager.GetDataFromObject(e.Data, "DraggedData");
 
           if (e.Effects != DragDropEffects.None)
           {
               //var collection = (sender as TextBox).Text;
               //collection.Remove(draggedItem);
           }
       }
 
       private void OnDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
       {
           var draggedItem = DragDropPayloadManager.GetDataFromObject(e.Data, "DraggedData");
           var details = DragDropPayloadManager.GetDataFromObject(e.Data, "DropDetails") as DropIndicationDetails;
           var itemsType = (this.AssociatedObject.Text);
 
           //if (details == null || draggedItem == null || draggedItem.GetType() != itemsType)
           //{
           //    return;
           //}
 
           if (e.Effects != DragDropEffects.None)
           {
               var collection = (sender as TextBox);
               if (collection != null) collection.Text = collection.Text;
           }
       }
 
       private void OnDragOver(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
       {
           //var draggedItem = DragDropPayloadManager.GetDataFromObject(e.Data, "DraggedData");
           //var itemsType = (this.AssociatedObject.ItemsSource as IList).AsQueryable().ElementType;
 
           //if (draggedItem.GetType() != itemsType)
           //{
           //    e.Effects = DragDropEffects.None;
           //}
 
           //var dropDetails = DragDropPayloadManager.GetDataFromObject(e.Data, "DropDetails") as DropIndicationDetails;
           //dropDetails.CurrentDraggedOverItem = this.AssociatedObject;
           //dropDetails.CurrentDropPosition = Controls.DropPosition.Inside;
 
           e.Handled = true;
       }
   }
Nick
Telerik team
 answered on 30 May 2014
1 answer
945 views
Hi there,

we're using the RadGridView in our MVVM application, so no code-behind or explicit C# code talking to the controls -

How can we specify that grouped rows are expanded by default in the XAML?
Grouping is achieved via ColumnGroupDescriptor in our case.

Thanks,
Jay
Yoan
Telerik team
 answered on 30 May 2014
1 answer
111 views
Hi,

I am using 2014.1.428.45 Telerik dll version. In this dll, while i was pasting the text continuously in the Radrichtextbox its simply keep on increasing the memory of the application.

And also I have used memory profiler to detect where the memory leaks.

please find attached files are classes that used for memory leaks.

Can any one please help me regarding this issue ?

Thanks and regards,
Sivalingam.
Petya
Telerik team
 answered on 30 May 2014
3 answers
113 views
Hi,

I am just trying to improve scroll performance, when the RowDetailsVisibilityMode is set to "Visible", because it is slow for complex detail controls.
Now I am doing this:

<DataTemplate x:Key="DetailTemplate">
    <ContentControl/>
</DataTemplate>

In code behind:

List<TextBlock> notInUse = new List<TextBlock>();

public DataListEditor()
{
    InitializeComponent();

    for (int i = 0; i < 100; ++i)
    {
        TextBlock tb = new TextBlock();
        notInUse.Add(tb);
    }

    dataListGrid.LoadingRowDetails += dataListGrid_LoadingRowDetails;
    dataListGrid.UnloadingRowDetails += dataListGrid_UnloadingRowDetails;
}

void dataListGrid_UnloadingRowDetails(object sender, Telerik.Windows.Controls.GridView.GridViewRowDetailsEventArgs e)
{
    ContentControl c = e.DetailsElement as ContentControl;

    TextBlock tb = c.Content as TextBlock;

    if (tb != null)
    {
        c.Content = null;
        notInUse.Add(tb);
    }
}

void dataListGrid_LoadingRowDetails(object sender, Telerik.Windows.Controls.GridView.GridViewRowDetailsEventArgs e)
{
    ContentControl c = e.DetailsElement as ContentControl;

    if (c.Content == null)
    {
        Binding b = new Binding("Roles[0].DisplayName");
        b.Source = e.Row.DataContext;

        TextBlock tb = notInUse[0];
        notInUse.RemoveAt(0);

        tb.SetBinding(TextBlock.TextProperty, b);
        c.Content = tb;
    }
}

In other words: I try to recycle detail controls, so that there is no need to recreate them. This works fine, when I am only scrolling. But if I resize the window, the DetailsPresenter of a row seems not to be measured to its content, so the text block is there with the right height, but its visual ancestors have a wrong height and the textblock is not visible. Is there a workaround to solve this?

Thanks
Yoan
Telerik team
 answered on 29 May 2014
8 answers
376 views
Hi,
I follow your demo: http://www.telerik.com/help/wpf/gridview-populating-datavirtualization.html and seems I missing something.

Use code first.

xaml:
-------------------------------
<telerik:RadGridView Grid.Row="1" Name="_grid" ItemsSource="{Binding Contacts}" AutoGenerateColumns="True" 
                             ShowColumnFooters="True"
                             ColumnWidth="*" AlternationCount="2" AlternateRowBackground="#FFEAEFF7" Background="#FFD2DEEF" EditTriggers="None"
                             telerik:StyleManager.Theme="Summer" HorizontalGridLinesBrush="White" VerticalGridLinesBrush="White">

 <telerik:RadDataPager Grid.Row="2" Source="{Binding ElementName=_grid, Path=Items}"
                              DisplayMode="FirstLastPreviousNextNumeric,Text" PageSize="18" />
-------------------------------

ViewModel:
-------------------------------
public VirtualQueryableCollectionView Contacts { get; set; }

public ContactViewModel()
        {
            var db = new PaperCRMContext();
            var query = db.Contacts.OrderBy(x => x.Id);
            Contacts = new VirtualQueryableCollectionView(query) { LoadSize = 10 };
        }
-------------------------------
When I run the project I receive error: 
{"There is already an open DataReader associated with this Command which must be closed first."}

When I remove .OrderBy(x => x.Id) i receive other error: 
{"The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'."}

At last when I remove { LoadSize = 10 }
I receive empty grid

Can someone help me what I miss here?

Best regards,
Saykor


Boris
Telerik team
 answered on 29 May 2014
2 answers
147 views
We are replacing our applications existing HTML editor with the Telerik RadRichTextBox.

One of our users noticed that her font was no longer available in the FontFamily combo.

I discovered that the font she could not find is a *.otf (OpenType) font.

Does the RadRichTextBox support *.otf (OpenType) fonts?
Petya
Telerik team
 answered on 29 May 2014
4 answers
461 views
Hi,,

How to set the selected points in RadCartesianChart with ScatterPointSeries from the View Model?


Thanks,,
Ahmed
Top achievements
Rank 1
 answered on 29 May 2014
1 answer
64 views
Hi!

I tried to set different themes for my application and I found out that all themes look like in the Sample WPF applications, except for the "Windows8" theme. RadWindow header in samples is different from that in my application. Can anyone tell me why?
Kalin
Telerik team
 answered on 29 May 2014
1 answer
68 views
Hi,

After updating the Telerik dll v2014.1.331.40, The RadFluidContentControl inside RadTileView is not working.

<telerik:RadFluidContentControl Margin="2"  ContentChangeMode="Manual"  State="Normal">
   // Content here is not rendering
<telerik:RadFluidContentControl.Content>

</telerik:RadFluidContentControl.Content>
</telerik:RadFluidContentControl

After commenting the telerik:RadFluidContentControl the content is visible. Any changes in Telerik dll v2014.1.331.40 ?

Regards
Siva
Pavel R. Pavlov
Telerik team
 answered on 29 May 2014
1 answer
115 views
Hello, everyone.

I am working on an MVVM / Prism application and I have run into a bit of  a snag on how to populate my PanelBar with items.  For reference: I am trying to create a layout similar to the one found here. On the referenced page assume that Products and Support are each their own separate modules, and that each item under them represents a view within that module. Now assume that there is security built around both Modules and Views so that only certain people can see them.  

I am already dynamically loading my modules via reflection, but I am at a loss on how to do dynamically load my views.  To register my views, I would typically do something like this:

RegionManager.Regions["NavRegion"].Add(Container.Resolve<DefaultView>(), "TheDefaultView");

Where "NavRegion" is a custom region that I have a RegionAdapter for.  The problem is that I don't see a way to setup my RegionAdapter to get my PanelBar to display in the manner I would like since I can't really build a Hierarchical structure in my RegionAdapter. Is there anyway that I could bind to an XML document that defines the structure of the items?  If there is a way to do that, is it possible to append to a bound xml datasource? What I mean is: Module1 has an XML document that defines what views to show, Module2 has an XML document that defines what views to show, and so on.

Thanks for any help you might be able to provide!

Pavel R. Pavlov
Telerik team
 answered on 29 May 2014
Narrow your results
Selected tags
Tags
GridView
General Discussions
Chart
RichTextBox
Docking
ScheduleView
ChartView
TreeView
Diagram
Map
ComboBox
TreeListView
Window
RibbonView and RibbonWindow
PropertyGrid
DragAndDrop
TabControl
TileView
Carousel
DataForm
PDFViewer
MaskedInput (Numeric, DateTime, Text, Currency)
AutoCompleteBox
DatePicker
Buttons
ListBox
GanttView
PivotGrid
Spreadsheet
Gauges
NumericUpDown
PanelBar
DateTimePicker
DataFilter
Menu
ContextMenu
TimeLine
Calendar
Installer and Visual Studio Extensions
ImageEditor
BusyIndicator
Expander
Slider
TileList
PersistenceFramework
DataPager
Styling
TimeBar
OutlookBar
TransitionControl
FileDialogs
Book
ToolBar
ColorPicker
TimePicker
MultiColumnComboBox
SyntaxEditor
VirtualGrid
Wizard
ExpressionEditor
NavigationView (Hamburger Menu)
WatermarkTextBox
DesktopAlert
BarCode
SpellChecker
DataServiceDataSource
EntityFrameworkDataSource
RadialMenu
ChartView3D
Data Virtualization
BreadCrumb
ProgressBar
Sparkline
LayoutControl
TabbedWindow
ToolTip
CloudUpload
ColorEditor
TreeMap and PivotMap
EntityFrameworkCoreDataSource (.Net Core)
HeatMap
Chat (Conversational UI)
VirtualizingWrapPanel
Calculator
NotifyIcon
TaskBoard
TimeSpanPicker
BulletGraph
Licensing
WebCam
CardView
DataBar
FilePathPicker
PasswordBox
SplashScreen
Rating
Accessibility
Callout
CollectionNavigator
Localization
AutoSuggestBox
Security
VirtualKeyboard
HighlightTextBlock
TouchManager
StepProgressBar
Badge
OfficeNavigationBar
ExpressionParser
CircularProgressBar
SvgImage
PipsPager
SlideView
AI Coding Assistant
+? more
Top users last month
Cynthia
Top achievements
Rank 1
Iron
Jesse
Top achievements
Rank 2
Iron
Toby
Top achievements
Rank 3
Iron
Iron
Iron
Danielle
Top achievements
Rank 1
Iron
Iron
Joel
Top achievements
Rank 3
Bronze
Bronze
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Cynthia
Top achievements
Rank 1
Iron
Jesse
Top achievements
Rank 2
Iron
Toby
Top achievements
Rank 3
Iron
Iron
Iron
Danielle
Top achievements
Rank 1
Iron
Iron
Joel
Top achievements
Rank 3
Bronze
Bronze
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?