How cam I Implement a delegatecommand to return a List<t>

private DelegateCommand _compute;
        public DelegateCommand Compute
        {
            get
            {
                if (_compute == null)
                    _compute = new DelegateCommand(GetData, CanExecute);

                return _compute;
            }
        }

I want to return a List <T> in my action method
 public List<T> GetData()
LVL 1
countrymeisterAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
You have a WCF topic, but DelegateCommand for me is from WPF.

Is this what you are referring to?

Using Delegate Commands with WPF Views (UPDATED)
http://consultingblogs.emc.com/dariuscollins/archive/2009/11/23/using-delegate-commands-with-wpf-views.aspx
0
countrymeisterAuthor Commented:
Ok, Learned One thanks for pointing I have it in the wrong section.
I have it under C# and .NET Programming too.

But that link does not answer my question. I need to know if it is possible to return a type in the delegate command , from the reading I have done the Action has a void return type.
So I think you cannot have a return type.
0
Bob LearnedCommented:
That article wasn't intended to be a solution, but a way to validate that your question was truly a WPF question.

What do you need to do with the return?  I haven't really used the DelegateCommand for anything other than the simple case of passing a parameter and a command that uses binding.
0
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

countrymeisterAuthor Commented:
On my button click I need to fetch some data and stiore the result set
0
Bob LearnedCommented:
I wouldn't think that the use case that you have described would suggest that the DelegateCommand is not a good choice for what you need to do.

Can you describe the UI chain of events that lead you to believe that the DelegateCommand was a necessary choice?
0
countrymeisterAuthor Commented:
I am using MVVM pattern in my WPF application , and when the user clicks on a button on the UI (View) and then in the View Model I would like to get some data from a wcf service
0
Bob LearnedCommented:
Can you show me the binding for the view please?
0
countrymeisterAuthor Commented:
Hi ! LearnedOne

Here is the code snippet.

View

<Button Grid.Row="1" Grid.Column="4" HorizontalAlignment="Left" VerticalAlignment="Top" ToolTip="Compute "  MaxWidth="50"  Command="{Binding ComputeData}"  >
                                        <Button.Template>
                                            <ControlTemplate>
                                                <Border HorizontalAlignment="Center" VerticalAlignment="Bottom" >
                                                    <Image Source="/Views/Images/calc.ico"
                                                    Width="30"
                                                    Height="20"/>                                        
                                                </Border>
                                            </ControlTemplate>
                                        </Button.Template>
                                    </Button>


ViewModel

 public DelegateCommand ComputeData
        {
            get
            {
                if (_computePnL == null)
                    _computePnL = new DelegateCommand(GetData, CanExecute);

                return _computePnL;
            }
        }

       public void GetPnLData() // need this to pass a list
        {          
            //get a list of records from the wcf service
          }
0
Bob LearnedCommented:
The problem with the DelegateCommand is that the argument is an Action type, not a Func type, so it cannot return any values.

 public DelegateCommand(Action<object> execute, Predicate<object> canExecute)

I don't see what control you are trying to bind the data to.
0
countrymeisterAuthor Commented:
I just mentioned that
"But that link does not answer my question. I need to know if it is possible to return a type in the delegate command , from the reading I have done the Action has a void return type.
So I think you cannot have a return type. "

So is there any other command that you can think of, or any other mechanism I could use.
0
Bob LearnedCommented:
I am not that familiar with WPF and MVVM, so it would be difficult for me to suggest something new.  You might want to delete this question, and ask it again, and maybe you would get a better WPF expert.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
countrymeisterAuthor Commented:
I will give you the points for trying
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.