开发者

How to bind between listView with two column and database items?

I define some listview that each row contain 2 button. Each button contain text that exist in the sql server database.

I want to bind the button text to the database - but i don't know how to do it because of the special listview stru开发者_运维问答cture.


You should set the ItemsSource property of the ListView (any particular reason you're not using a ListBox?) to a collection containing domain models which have been populated by the database. If you are using codebehind, then you can use listViewName.ItemsSource = myListOfDomainObjects. If you are using MVVM, then expose a property on your viewmodel, and use a binding expression in the XAML.

<ListView x:Name="MyList" ItemsSource="{Binding MyViewModelCollectionProperty}"> 
  ...
</ListView>

If your domain model has an e.g. 'Name' string property, then you can use this as the button text in your ItemTemplate by using:

<Button Content="{Binding Name}" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜