.NET Framework Bookmark and Share   
 index > Windows Presentation Foundation (WPF) > WPF binding to specific item in list
 

WPF binding to specific item in list

Hello!

I have problem with binding content property of Label to specific item in list.

I know that I can do something like this

Public Property ListExample As List(Of String)
Get
     Return _listExample
End Get
Set(value As List(Of String))
     _listExample
End Set
End Property

<Label Content="{Binding Path=ListExample[2]}"/>


But what should I do to binding to the specific element from another property. For example:

Public Property ListExample As List(Of String)
Get
     Return _listExample
End Get
Set(value As List(Of String))
     _listExample
End Set
End Property

Public Property SpecificItem As Integer
Get
    Return _specificItem
End Get
Set(value As Integer)
   _specificItem = value
End Set
End Property


<Label Content="{Binding Path=ListExample[SpecificItem]}"/>


This code doesn't work correctly.

Can anybody help me?
Thanks in advance


coolerwl
Ideally you should bind directly to the object in question and not try to find it through a list. If you are already creating a SpecificItem property, why not create another property that exposes your object in question?

Otherwise, you should create a converter that takes your ListExample and an index as a parameter and returns the object at that index.

http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter.aspx
Adam Sills

You can use google to search for other answers

Custom Search

More Threads

• Stopping windows from forcing the width of a Thumb
• Animate shaders from c# code
• add app.xaml to exiting 2.0 application
• Can't Data Bind to Dictionary<int, String>
• Graphic distortion in WPF applications?
• Get All Object has Custom Attached Properties
• WPF Browser application and WPF application flexibility questions
• 2 Projects in same Solution that share files?
• How to print custom control with FixedDocument ?
• ListView Multiple ColumnHeaders Displaying info