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

How to bind DataContext to drag visual with dynamic templates

5 Answers 14 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Maurice
Top achievements
Rank 1
Maurice asked on 30 Jun 2017, 06:11 AM

When creating the drag visual in codebeind, I am not seeing the data being bound to theTileViewItem, although the styles and templates are being applied, how can I get the data to bind?

01.private void OnDragInitialize(object sender, DragInitializeEventArgs args)
02.    {
03.      var data = ((RadRadioButton)args.OriginalSource).DataContext as ITile;
04. 
05.      var payload = DragDropPayloadManager.GeneratePayload(null);
06.      payload.SetData("DragData", data);
07. 
08.      args.Data = payload;
09.      args.AllowedEffects = DragDropEffects.All;
10.      args.DragVisual = new RadTileViewItem
11.      {
12.        DataContext = data,
13.        ContentTemplate = Application.Current.FindResource("DashboardTileView_ContentTemplate") as DataTemplate,
14.        HeaderTemplate = Application.Current.FindResource("DashboardTileView_ItemTemplate") as DataTemplate,
15.        Style = Application.Current.FindResource("DashboardTileView_ItemStyle") as Style
16.      };
17.    }

 

Thank you,
Maurice

5 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 04 Jul 2017, 02:25 PM
Hello Maurice,

Rather than set the DataContext of the RadTileViewItem to the data object could you please try setting the Content property instead similarly to how this has been done in the following article and let me know if this works for you?

If that is not the case, would it be possible for you to provide more details on your exact setup, or ideally open a new support ticket and send over a sample project so that I can better assist you with this?

I'm looking forward to your reply.

Regards,
Dilyan Traykov
Progress Telerik
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 you to write beautiful native mobile apps using a single shared C# codebase.
0
Maurice
Top achievements
Rank 1
answered on 05 Jul 2017, 06:37 AM

Hi Dilyan,

I did try that first after using that article as a reference (before my original post) with the opposite effect, i.e. data was showing but the template/s was not being applied. I have tried to re-apply the logic and have come up against some other issues. I will re-try once I get back to that area and let you know the outcome.

 

Thank you,
Maurice

0
Dilyan Traykov
Telerik team
answered on 05 Jul 2017, 11:40 AM
Hello Maurice,

Do let me know how this goes. I'm looking forward to your reply.

Regards,
Dilyan Traykov
Progress Telerik
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 you to write beautiful native mobile apps using a single shared C# codebase.
0
Maurice
Top achievements
Rank 1
answered on 09 Jul 2017, 01:57 PM

Apologies for the delay, I have re-tried the approach (which I am sure I tried previously) and it has worked successfully this time.

Thanks again,
Maurice

0
Dilyan Traykov
Telerik team
answered on 10 Jul 2017, 11:16 AM
Hello Maurice,

I'm glad to hear that everything works as expected now. If I can be of any further assistance, please inform me.

Regards,
Dilyan Traykov
Progress Telerik
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
DragAndDrop
Asked by
Maurice
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Maurice
Top achievements
Rank 1
Share this question
or