Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I create the correct ICommand (or RelayCommand)

Posted on 2010-11-09
4
Medium Priority
?
971 Views
Last Modified: 2012-05-10
I want to create:

AllCustomers as ObservableCollection(Of Customer)

where Customer is:

Public Class Customer
  Public Property ID as integer
  Public Property Name as String
  Public Property Cmd as ICommand (or RelayCommand)
End Class

So that when AllCustomers is bound to the ItemSource of a ListBox
and the Name and ID are shown via a data template, I can click the Name or ID and go to a routine where I can know what the ID of the customer is.

I know this is doable and I probably need another class that will inherit from ICommand or RelayCommand, but I don't understand WPF commanding well enough to do it.

Can someone help?
0
Comment
Question by:AIBMass
  • 2
4 Comments
 

Author Comment

by:AIBMass
ID: 34098668
I guess I should have added that I'm starting with a dataset of customer info....looping through the rows building my collection....and wondering how to build the command.

Thx
0
 
LVL 29

Accepted Solution

by:
Gautham Janardhan earned 1500 total points
ID: 34101383
you need to inherit from ICommand and create a command of your own, take a look at this tutorial for more info

http://www.codeproject.com/KB/WPF/wpfcommands.aspx


once you have your command, you can bind these to the button's command property ,(you may need to modify the style of the button so that it would look less like a button and more like a label in ur case)
0
 

Author Closing Comment

by:AIBMass
ID: 34101919
I had already found this article, but it was not as easy to follow as I hoped.

Nonetheless, it contained the correct info and I was able to figure it out.
0
 
LVL 27

Expert Comment

by:MikeToole
ID: 34103482
>> ... I can click the Name or ID and go to a routine where I can know what the ID of the customer is.

Is the requirement to call the routine every time a selection is made in the list?
If so you can bind the Listbox's SelectedItem property to a Customer-type property in your class - SelectedCustomer in the example below.
The setter is then called whenever the selection is changed , passing the Customer instance as the new value, and there's no need for a command.

                   SelectedItem="{Binding SelectedCustomer}">
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

927 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