无法在WPF应用程序中实现ObjectDataProvider [英] Not able to implement ObjectDataProvider in WPF Application

查看:72
本文介绍了无法在WPF应用程序中实现ObjectDataProvider的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在尝试学习ObjectDataProvider ,但是现在我被卡住了!
这就是我想要做的:
课程:

Hello everyone,

I am trying to learn ObjectDataProvider but now I am stuck!
This is what I am trying to do:
Classes :

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


我的XAML:


My XAML :

<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>


但是它不会显示MyIntIsHere类的整数``a''.

我缺少什么?


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

What am I missing?

推荐答案

我已经自己解决了这个问题!
我读了几本书,但是没有正确地介绍ObjectDataProvider,因此不得不做更多的谷歌搜索"并了解更多有关它的信息.
现在我已经很了解了!
因此,我在问题上并没有做太多更改,但是对DisplayIt类及其函数ShowIt()进行了一些更改.
因此,答案就在问题本身中了!
现在可以正常工作了! :)
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! :)


这篇关于无法在WPF应用程序中实现ObjectDataProvider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆