|
-
Apr 2nd, 2010, 03:51 PM
#1
Thread Starter
Lively Member
How to: Create an array of controls in WPF
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
-
Apr 2nd, 2010, 04:18 PM
#2
Re: How to: Create an array of controls in WPF
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
-
Apr 2nd, 2010, 04:23 PM
#3
Thread Starter
Lively Member
Re: How to: Create an array of controls in WPF
 Originally Posted by 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
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. 
I've:
Code:
<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?
Code:
ListCovers.Items.add("Text")
, can only add text, not images
Last edited by Nikole; Apr 2nd, 2010 at 09:38 PM.
-
Apr 2nd, 2010, 09:31 PM
#4
Hyperactive Member
Re: How to: Create an array of controls in WPF
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.....
-
Apr 4th, 2010, 10:10 PM
#5
Thread Starter
Lively Member
Re: How to: Create an array of controls in WPF
-
Apr 5th, 2010, 01:13 AM
#6
Hyperactive Member
Re: How to: Create an array of controls in WPF
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:
Code:
<!--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
-
Apr 5th, 2010, 07:27 AM
#7
Thread Starter
Lively Member
Re: How to: Create an array of controls in WPF
 Originally Posted by 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:
Code:
<!--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 
Gracias, probaré el código y te dire después.!
-
Apr 5th, 2010, 01:20 PM
#8
Thread Starter
Lively Member
Re: How to: Create an array of controls in WPF
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ómo agrego un dato a este listview y especifico la imagen y el texto? con ListBox.items.add? pero cómo le especifico al listbox cual es la imagen? y cual es el texto?
-
Apr 6th, 2010, 04:14 PM
#9
Hyperactive Member
Re: How to: Create an array of controls in WPF
Well, if you don't want to use data binding you could create a custom control and add it directly to the listbox.
-
Apr 6th, 2010, 09:30 PM
#10
Frenzied Member
Re: How to: Create an array of controls in WPF
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.
Code:
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|