WPF - Pass Command Parameter to RelayCommand  - Need a simple example

Posted on 2012-08-23
Medium Priority
Last Modified: 2012-08-23
I need a working example of how to pass a parameter to a Relay Command.

I have simple hyperlink button. When the button is clicked I need to pass a string parameter to the command - the hyperlink will then open a document using the parameter passed

  <Hyperlink Command="{Binding Open_Doc_Command}" CommandParameter="{Binding Path=somefilename}" >
                                            Open Document
Question by:JElster
1 Comment
LVL 14

Accepted Solution

Vel Eous earned 2000 total points
ID: 38325111
Something like the following?

private RelayCommand m_Open_Doc_Command;
public System.Windows.Input.ICommand Open_Doc_Command
		if (m_Open_Doc_Command == null)
			m_Open_Doc_Command = new RelayCommand(param => Open_Doc(param));
		return m_Open_Doc_Command;

private void Open_Doc(object obj)
	string filename = obj as string;
	// do something

Open in new window


Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question