|
-
Mar 6th, 2012, 04:19 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Listbox items
I have this code and i now want to add items to my listbox in this format, my data i'm getting is from a xml code which I'm reading from my vb.net code
Code:
<Windows.Resource>
<DataTemplate x:Key="EmployeeDataTemplate">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Margin="5" BorderBrush="Black" BorderThickness="1">
<Image Source="{Binding Path=Image}" Stretch="Fill" Width="50" Height="50" />
</Border>
<StackPanel Grid.Column="1" Margin="5">
<StackPanel Orientation="Horizontal" TextBlock.FontWeight="Bold" >
<TextBlock Text="{Binding Path=Firstname, FallbackValue=FirstName}" />
<TextBlock Text="{Binding Path=Lastname, FallbackValue=LastName}" Padding="3,0,0,0"/>
</StackPanel>
<TextBlock Text="{Binding Path=Age, FallbackValue=Age}" />
<TextBlock Text="{Binding Path=Role, FallbackValue=Role}" />
</StackPanel>
</Grid>
</DataTemplate>
</Windows.Resource>
<Listbox>
..
</Listbox>
-
Mar 10th, 2012, 03:39 PM
#2
Re: Listbox items
In code you can do this (it is c#, converting to vb is really simple):
Code:
DataSet Ds = new DataSet();
Ds.ReadXml("E:\\doc.xml");
ListBox1.DataSource = Ds;
ListBox1.DataTextField = "DocumentId";
ListBox1.DataValueField = "DocumentTitle"
ListBox1.DataBind();
If you want to bind in the XAML, you should load the dataset and bind it in XAML using :
Code:
<Listbox ItemSource = "{Binding DS}"/>
Remeber to make DS a property of the class (and use descent names )
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
|