Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7865551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:07:27+00:00 2026-06-03T00:07:27+00:00

I am having some repeating code in views, that are part of drag&drop operations.

  • 0

I am having some repeating code in views, that are part of drag&drop operations. I have an ICommand on ViewModelBase that handles required operations on model for drag&drop operation. Since I was trying to avoid passing UI event arguments to ViewModel, I needed to make my own argument type that would be passed to DropCommand. So basically my code in View’s code behind looks like this:

// get data required for ordering operation
var args = MyHelperClass.OnDropCompleted(a); // where a is an argument from UI drop event

// execute command
if (args != null) ViewModel.DropCommand.Execute(args);

This works fine, however, this code is repeated on each view. My idea is to add a DropCommand to my custom UI control, so I could assign a ICommand binding in xaml

DropCommand={Binding DropSommand} <-- binds to ViewModel's DropCommand

Now, I could handle drop event in my custom UI control, and invoke a command on viewmodel and pass it calculated argument.

Problems:

1) I would like to subscribe to Drop operation only if DropCommand’s binding is set in xaml. How can i Check if this binding is set?

2) After I have created the argument to be passed to ViewModel’s ICommand, I would like to invoke this command from code. How can I do this?

Edit: I also have the following binding scenario:

DropCommand={Binding DataContext.DropCommand, elementName=window}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:07:28+00:00Added an answer on June 3, 2026 at 12:07 am

    Within your drop event handler in your custom control’s codebehind:

    var bindingExpression = GetBindingExpression(DropCommandProperty);
    if  (bindingExpression != null) 
    {
        var command = (ICommand)bindingExpression.ParentBinding.Source;
        command.Execute(/* your special argument here */);
    }
    

    The presence of a BindingExpression tells you that something is bound, and you can get to the Source of that binding through the BindingExpression‘s ParentBinding property.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some troubles with binding data. I have an application that contains a
I have some asp.net code that populates the fields in a LINQ to SQL
I'm having a really nasty problem with some code that I've written. I found
I am having a strange problem in my code. I have many asserts scattered
I have a PHP site I'm building and I seem to be having some
I am having some trouble structuring my ReportFrame.SourceURL. My code as follows in my
I am having some difficulty dealing with memory leaks in the following code. Using
I am having trouble googling this. In some code I see name = name.replace(/[\[]/,\\\[).replace(/[\]]/,\\\]);
I have downloaded the Kohana Pagination module from Git and have been having some
I'm having some trouble with replacing a portion of a file in binary mode.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.