How to bind DataContext to drag visual with dynamic templates

6 posts, 0 answers
  1. Maurice
    Maurice avatar
    8 posts
    Member since:
    Feb 2014

    Posted 30 Jun Link to this post

    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

  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    603 posts

    Posted 04 Jul Link to this post

    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 allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. Maurice
    Maurice avatar
    8 posts
    Member since:
    Feb 2014

    Posted 05 Jul in reply to Dilyan Traykov Link to this post

    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

  4. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    603 posts

    Posted 05 Jul Link to this post

    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 allow you to write beautiful native mobile apps using a single shared C# codebase.
  5. Maurice
    Maurice avatar
    8 posts
    Member since:
    Feb 2014

    Posted 09 Jul in reply to Dilyan Traykov Link to this post

    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

  6. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    603 posts

    Posted 10 Jul Link to this post

    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.
Back to Top