0

Possible Duplicate:
Bind to a method in WPF?

How do i go about doing method binding in xaml?

I create a method to return a string and this returned string will be show on a datagrid column.

Community
  • 1
  • 1
kkh
  • 4,799
  • 13
  • 45
  • 73

3 Answers3

1

As the others mentioned, and your interest in concatenating the 3 "B" elements, create a property and return something like

public string YourMultiPartString
{
   get { return FirstB.Whatever + SecondB.Whatever + ThirdB.Whatever; }
} 

and set your binding to this "YourMultiPartString" property.

If your "B" object has some other internal function that does OTHER actions to get the string, just change to reflect that... such as

public string YourMultiPartString
{
   get { return FirstB.SomeMethod() + SecondB.SomeMethod() + ThirdB.SomeMethod(); }
} 
DRapp
  • 47,638
  • 12
  • 72
  • 142
0

Well if you ask me i would have a property containing that value and change the property when you call the method, this way you would resolve your problem..

Peter
  • 37,042
  • 39
  • 142
  • 198
  • hmm what i have in mind is that i have an object A consisting of 3 objects of type B. each object B has a string value and what I want to display on a cell is the concatenation of the 3 strings together, hence binding to a method to return the concatenation. Is this possible? – kkh Oct 27 '11 at 10:14
  • I do not know of any way to bind to the result of a method, so my guess your best way to do this is a property that contains the result of the method and bind to that property... – Peter Oct 27 '11 at 10:15
0

Bind to a property that returns the result of the method.

Ritch Melton
  • 11,498
  • 4
  • 41
  • 54