WPF Reflections

Dec 6 2007   3:42PM GMT

Current item in binding

Mark Shurmer Profile: MarkWPF

The question i was faced with was how to bind to a current item in an array. Why? I wanted to display the result of the ToString() method on the whole object – it should display something like ‘buy 100 abc.o @ 50’

I had an array (of Equities, but it could have been anything), and some xaml binding to it:

<StackPanel DataContext={x:Static EquitiesModel.Equities}>
<TextBlock Text={Binding} />
<ListBox ItemsSource={Binding}IsSynchronizedWithCurrentItem=True />
</StackPanel>

That didn’t work because the {Binding} binds to the whole array, and i just needed the current item. It turned out to be some syntax that I hadn’t seen since XPath:

<StackPanel DataContext={x:Static EquitiesModel.Equities}>
<TextBlock Text={Binding /} />
<ListBox ItemsSource={Binding}IsSynchronizedWithCurrentItem=True />
</StackPanel>

Lo and behold, it used the ToString() method, and I was happy!

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: