Results 1 to 2 of 2

Thread: [RESOLVED] Listbox items

  1. #1
    Fanatic Member
    Join Date
    Dec 09
    Location
    Milan
    Posts
    810

    Resolved [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>

  2. #2
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 02
    Location
    Eygelshoven
    Posts
    1,556

    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 )
    VB6 & C# (WCF LINQ) mostly


    If you need help with a WPF/WCF question post in the NEW WPF & WCF forum and we will try help the best we can

    My site

    My blog, couding troubles and solutions

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •