Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hi all,

I am developing a Windows Phone 7 project.

I have created a custom object. I have done this by right-clicking the project and choosing Add - Windows Phone User Control.

For the benefit of this post, the object that I have created is a rectangle which contains a textblock. I have named this custom user control myCustomControl1.

On my windows phone page, I have created a listbox, and added myCustomControl1 to the list box.

I have bound the list box to an array of items coming from a DB. For each item, I am displaying one CustomControl1 object. This currently works as planned. For example if 12 items are in the item array then 12 CustomControl1 controls are appearing within the listbox on the page.

However, my problem is, the textblock within my CustomControl1 object needs its .Text attribute to be bound to a corresponding value from each item in the item array. For example, if the item array was:

Cat
Dog
Sheep
Horse
Monkey

then the first customcontrol1's textblock item should have its text set to Cat, the second to Dog, etc.

If i was creating the datatemplate there and then (as opposed to using a custom user control), I could add a <textblock> item in the datatemplate, and bind it accordingly.

However, as I am using a custom control, I don't want to be adding new textblocks and having to design them on the page. Surely the whole point of creating custom controls is that I can specify externally the design of the item, and then bind the specific values when it is used on each page...

So to summarise, I need assistance in simply binding the custom control's existing textblock item to an array stored on that page, ideally done from within the xaml.

Thanks!
Posted

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