Im currently developing an Windows Phone 7.0 Application with C#. I got an Listbox whichs items is based on the results of an WCF-Service. I’ve created my own object which contains a few values that have been fetched from an database. The problem is that i don’t know how to change the content of each Listbox Item depending on the values of that items parameters that was fetched using the webservice.
Structure:
- User enters the XAML Page
- An connection is being opened between the client and the webservice
- The webservice returns an
List<Friend>The important parameter inside Friend is calledVerified - The listbox items is set using:
lstFriends.ItemsSource = e.Result;
What i want to do:
- I want to check in each Listbox Item after the parameter
Verifiedand check it’s value. - Depending on if the parameter is true or false a TextBlock inside the Listbox Item should have different text.
Thanks
This is probably an ugly way to do it with no code-behind, but what you could do is create a template for your listboxitem that includes two textblocks (something) like this:
You would then have to write two converters: BoolToVisibilityConverter to change the boolean value of Verified to Visible if True and Collapsed if False for the first text block and ReverseBoolToVisibilityConverter to change the boolean value of Verified to Visible if False and Collapsed if True on the second text block. This way one textblock will always be visible in the listboxitem and one will always be collapsed, depending on the value of the Verified property.
If you don’t know how to do value converters, you can look HERE.
This isn’t tested and is not all of the code you’d need, but it should work. This assumes that the two different text blocks will always contain the same text and that the Verified property is a boolean property, if not then you might want to figure out another way to do it.
On second thought, you could just do ONE value converter and one textblock and convert the value of Verified to the text you want. That would be easier.