Click here to Skip to main content
15,918,211 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,

I am trying to learn ObjectDataProvider but now I am stuck!
This is what I am trying to do:
Classes :
VB
Class MyIntIsHere
 Dim a As Integer

 Public Property myA() as Integer
  Get
     Return a
  End Get
  Set(ByVal value as String)
     a=value
  End Set
 End Property

 Public Sub New(_a as Integer)
  a=_a
 End sub

End Class

Class DisplayIt
 Private lst As New List(of MyIntIsHere)

 Public Sub New()

 End Sub

 Public Function ShowIt() as List(of MyIntIsHere)
  lst.Add(new MyIntIsHere(1))
  return lst
 End Function

End Class

My XAML :
XML
<Window.Resources>
 <ObjectDataProvider x:key="MyProvider" ObjectType="{x:Type local:DisplayIt}" MethodName="ShowIt"/>
</Window.Resources>
Now i want to display it in a ListBox :
<ListBox ItemsSource="{Binding Source={StaticResource MyProvider}}" and other things >
<ListBox.ItemTemplate>
 <DataTemplate>
  <TextBlock Text="{Binding Path=myA}"/>
 </DataTemplare>
</ListBox.ItemTemplate>
</ListBox>

But it doesn't display the integer 'a' of class MyIntIsHere.

What am I missing?
Posted
Updated 8-Nov-10 2:01am
v7
Comments
Sandeep Mewara 25-Oct-10 9:20am    
Use PRE tags to format your code part. It makes the question readable.
Tarun.K.S 25-Oct-10 9:22am    
thanx Sandeep. Will do it next time.

1 solution

I have solved this by myself!
I read a couple of books but ObjectDataProvider was not properly covered, so had to do some more "Googling" and learnt more about it.
Now i have understood it very well!
So i didn't change much in the question but did some changes to the DisplayIt class and its function ShowIt().
So the answer now lies in the question itself!
Now it works smoothly! :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900