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 7191469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:44:07+00:00 2026-05-28T19:44:07+00:00

I have the following visual tree for which I am trying to send a

  • 0

I have the following visual tree for which I am trying to send a command through the EventToCommand.
The visual is as follow :

<Border Background="Gray" Grid.Row="0" Margin="2" VerticalAlignment="Bottom">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseDown">
                    <cmd:EventToCommand  
                Command="{Binding ShowVideosCmd}" 
                PassEventArgsToCommand="True" 
                CommandParameter="{Binding Videos}">
                    </cmd:EventToCommand>

                </i:EventTrigger>
            </i:Interaction.Triggers>
 </Border>

When clicking on the border where the command is attached to I get the following popup error :

“An unhandled exception of type ‘System.InvalidCastException’ occurred
in GalaSoft.MvvmLight.WPF4.dll

Additional information: Unable to cast object of type
‘System.Windows.Input.MouseButtonEventArgs’ to type
‘System.Windows.DependencyObject’. “

My command is then created in a viemModel as follow :

 ShowVideosCmd = new RelayCommand<DependencyObject>(
     (dpObj) =>
            { 
                 messenger.Default.Send<string>("ShowVideos");
            },
     (dpObj) => true
 );

What did I do wrong ?

  • 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-05-28T19:44:08+00:00Added an answer on May 28, 2026 at 7:44 pm

    The error message is quite self explanatory: in you RelayCommand<DependencyObject> you’ve expected the command parameter as a DependencyObject but you’ve got an MouseButtonEventArgs which is normal because you’ve subscribed to the MouseDown event.

    The EventToCommand when the event fires it exectues the command with one of following parameter:

    • If the the value of the CommandParameter is NOT null it uses it as the parameter so the command should look like: RelayCommand<typeOfTheSpecifiedCommandPameter>
    • If the PassEventArgsToCommand='true' and the value of the
      CommandParameter is null it uses the eventargs as the command
      parameter. So you need to define your command as
      RelayCommand<MouseButtonEventArgs>.
    • If PassEventArgsToCommand='false' and the CommandParameter is null it does not execute the command at all.

    Note:

    So you need to define differently your command for the two cases. At the need you have to use RelayCommand<object> and check the parameter type. That’s why I think it is bad practice to use PassEventArgsToCommand and CommandParameter at the same time.

    Back to the exception:

    In your case it seams CommandParameter="{Binding Videos}" returns null that is why you get the MouseButtonEventArgs as the command parameter.

    To figure out why {Binding Videos} is null you can check the Output window in VS during runtime looking for binding errors.

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

Sidebar

Related Questions

Hi I have a visual studio project which includes postbuildevents in the following form:
I have a small testview in Silverlight which consists of the following grid: <Grid
I have the following Visual Basic 6.0 function which writes an ANSI string to
Hey; I have the following visual hyerarchy in a usercontrol: Grid -> Canvas ->
I have the following code example for Visual C++ which creates an ActiveX object
I have the following configuration: Visual Studio Team System 2008 SQL Server Developer Edition
I have the following code in Visual Studio 2005. Dim OutFile As System.IO.StreamWriter Try
Maybe this is a dumb question, but I have the following behavior in Visual
I have the following piece of code in Visual C++ 2005 : : class
Visual Studio C++ 2008 I have the following code in my server.h file. #if

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.