0

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

1 Answer 1

1

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}" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.