# .NET and More > WPF, WCF, WF >  How to: Create an array of controls in WPF

## Nikole

Hi, i'm using Expression Blend to make an user interface. I put a text box (Text1) and when i copy the same control in the form, the new control get the name Text1_Copy. how can i create an array of controls? I mean Text1(0), text1(1), text1(2)??, please help  :Frown:   :Sick:

----------


## techgnome

Don't think you can... at least not at design time... you can load the text boxes into an array or a list(of) at runtime. 

Why do you need a control array?

-tg

----------


## Nikole

> Don't think you can... at least not at design time... you can load the text boxes into an array or a list(of) at runtime. 
> 
> Why do you need a control array?
> 
> -tg



I've started yesterday with WPF and Expression Blend. And I don't know how to use the ListView to show items like this example. Its more easy for me add controls and load images and text at runtime., like in VB6.   :Blush: 


I've:



```
<ListView Name="ListCovers" Margin="50,0,50,0" SelectionMode="Single" Background="Transparent">
                <StackPanel Orientation="Vertical">
                     <Image Source="mariah.jpg"></Image>
					 <TextBlock Text="Hola" Foreground="White" Cursor="Hand" FontSize="29.333"/>
                </StackPanel>
</ListView>
```

How can i add more images and text from VB code?


```
ListCovers.Items.add("Text")
```

, can only add text, not images  :Roll Eyes (Sarcastic):

----------


## Pac_741

In order to display items in such a way, I would use one of these 2 methods:
1- Using Data templates.
2- User Controls

Do don't necessarily have to use the ListView control to achieve that.

Good Luck. 

P.S: When I started with WPF everything was so confusing because I never took the time to read basic concepts before starting to work. I would advice you to read some basic documentation about WPF, mainly DataTemplates, Controls, etc.....

----------


## Nikole

> In order to display items in such a way, I would use one of these 2 methods:
> 1- Using Data templates.
> 2- User Controls
> 
> Do don't necessarily have to use the ListView control to achieve that.
> 
> Good Luck. 
> 
> P.S: When I started with WPF everything was so confusing because I never took the time to read basic concepts before starting to work. I would advice you to read some basic documentation about WPF, mainly DataTemplates, Controls, etc.....



Hi, i've tried for 3 days and i can't do a Listview like i want. Please, please, could you help me? could you make for me a ListView like the screenshot? and pupupate few images and text from code? i need it to understand the code and how it work , please, this is easy for u  :Frown:   .... (excuse my english)

----------


## Pac_741

Programming doesn't work that way, you have to have a certain knowledge of what you are doing, which you could get by reading some stuff.

You are right this is simple for me, but you can achieve this be reading some basic tutorials on DataTemplates, and Layouts.

This code can get you started:



```
        <!--ListView is not necessarily required here-->
        <!--Horizontal ScrollBar Visibility has to be disabled for layout to occur-->
        <ListBox x:Name="listbox"  ScrollViewer.HorizontalScrollBarVisibility="Disabled">
            <!--Items Template-->
            <!--If you want to create a media player you will have to 
                Investigate Data Binding-->
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <!--Width has to be set so items display properly-->
                    <StackPanel Width="50">
                        <Image Source="{Binding Path=image}"></Image>
                        <Label Content="{Binding Path=artis}"></Label>
                    </StackPanel>
                </DataTemplate>                
            </ListBox.ItemTemplate>
            <!--Items Panel-->
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
        </ListBox>
```


Please try to get to know WPF before starting to work with it, Good Luck  :Smilie:

----------


## Nikole

> Programming doesn't work that way, you have to have a certain knowledge of what you are doing, which you could get by reading some stuff.
> 
> You are right this is simple for me, but you can achieve this be reading some basic tutorials on DataTemplates, and Layouts.
> 
> This code can get you started:
> 
> 
> 
> ```
> ...


Gracias, probaré el código y te dire después.!

----------


## Nikole

Gracias Pac_741, te molesto con una ultima pregunta: we've "image" and "artist" variable in your xaml example. how can i add a new item without databinding? c&#243;mo agrego un dato a este listview y especifico la imagen y el texto? con ListBox.items.add? pero c&#243;mo le especifico al listbox cual es la imagen? y cual es el texto?  :wave:

----------


## Pac_741

Well, if you don't want to use data binding you could create a custom control and add it directly to the listbox.

----------


## DeanMc

As Pac said you need to figure out the basic structure of programming and wpf first. Using that picture as an example the best way to go about it would be to create a class that contains the information you need so for instance.




```
Class Album
     ArtistName
     AlbumName
     ...
End Class
```

As you can see our class only has data in it and only data applying to a single entity, so we would need to create one of these classes for each album we wanted to display for that we can put them into a ListOf(Album).

All you need to do then is to bind or insert this list using a template like the one shown previous and you are good to go.

----------

