Shantanu Gupta
Shantanu Gupta

Reputation: 21108

What's the issue with this WPF binding

What's the issue with this WPF binding

<TextBox Name="TagNumberTextBox" Style="{StaticResource TextBoxStyle}" 
Width="200" CharacterCasing="Upper" Text="{Binding Tags, Path=[0]}"/>

I am getting error on Text="{Binding Tags, Path=[0]}"

The property 'Path' is set more than once.

However I am expecting that this issue could be because of WCF service binding. My WCF Service is not being invoked.

WPF Screen has a DataContext which has one of the property Tags which is an Observable collection. I am trying to bind it to first element of that collection.

Upvotes: 0

Views: 219

Answers (2)

ColinE
ColinE

Reputation: 70160

When you create a binding of this form {Binding Foo}, the Foo component is the property path. It is a shorthand form where you can omit the Path= component.

Therefore {Binding Tags, Path=[0]} is setting the path to both Tags and [0].

I suspect you are wanting to do this {Binding Path=Tags[0]} - or in the shorthand form {Binding Tags[0]}

Upvotes: 6

Ken Smith
Ken Smith

Reputation: 20445

Try Text="{Binding Path=Tags[0]}".

Upvotes: 2

Related Questions