Click here to Skip to main content
15,915,164 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: TextBolck move using up & down arrow?? Pin
urooj_mahmood17-Mar-10 3:37
urooj_mahmood17-Mar-10 3:37 
GeneralRe: TextBolck move using up & down arrow?? Pin
urooj_mahmood30-Mar-10 2:31
urooj_mahmood30-Mar-10 2:31 
Questionhow can I add mutiple layers on SilverLight User Control?? Pin
urooj_mahmood9-Mar-10 19:50
urooj_mahmood9-Mar-10 19:50 
AnswerRe: how can I add mutiple layers on SilverLight User Control?? Pin
Abhinav S14-Mar-10 20:10
Abhinav S14-Mar-10 20:10 
QuestionSome good WPF books? Pin
Dan Mos9-Mar-10 12:15
Dan Mos9-Mar-10 12:15 
AnswerRe: Some good WPF books? Pin
carlecomm9-Mar-10 18:13
carlecomm9-Mar-10 18:13 
GeneralRe: Some good WPF books? Pin
Dan Mos10-Mar-10 5:19
Dan Mos10-Mar-10 5:19 
AnswerRe: Some good WPF books? Pin
Richard MacCutchan9-Mar-10 21:40
mveRichard MacCutchan9-Mar-10 21:40 
QuestionWPF mapping with Dependency properties Pin
Juan Pablo G.C.9-Mar-10 1:05
Juan Pablo G.C.9-Mar-10 1:05 
AnswerRe: WPF mapping with Dependency properties Pin
Pete O'Hanlon9-Mar-10 1:46
mvePete O'Hanlon9-Mar-10 1:46 
QuestionFormat datetime value in XMAL Pin
Garrisoft9-Mar-10 1:03
Garrisoft9-Mar-10 1:03 
AnswerRe: Format datetime value in XMAL Pin
Abhinav S14-Mar-10 21:11
Abhinav S14-Mar-10 21:11 
QuestionHow to avoid 'System.StackOverflowException' when saving a canvas in a xaml Pin
Bhagya Thambugala8-Mar-10 6:22
Bhagya Thambugala8-Mar-10 6:22 
QuestionDatabinding to a single element from RIA [modified] Pin
Pankaj Nikam8-Mar-10 5:14
professionalPankaj Nikam8-Mar-10 5:14 
QuestionListView issues Pin
#realJSOP6-Mar-10 3:37
professional#realJSOP6-Mar-10 3:37 
AnswerRe: ListView issues Pin
Eslam Afifi6-Mar-10 8:19
Eslam Afifi6-Mar-10 8:19 
GeneralRe: ListView issues Pin
#realJSOP6-Mar-10 9:35
professional#realJSOP6-Mar-10 9:35 
GeneralRe: ListView issues Pin
Eslam Afifi6-Mar-10 10:51
Eslam Afifi6-Mar-10 10:51 
GeneralRe: ListView issues Pin
Pete O'Hanlon6-Mar-10 11:14
mvePete O'Hanlon6-Mar-10 11:14 
GeneralRe: ListView issues Pin
Eslam Afifi6-Mar-10 12:27
Eslam Afifi6-Mar-10 12:27 
GeneralRe: ListView issues Pin
Pete O'Hanlon6-Mar-10 12:34
mvePete O'Hanlon6-Mar-10 12:34 
GeneralRe: ListView issues Pin
Eslam Afifi6-Mar-10 13:02
Eslam Afifi6-Mar-10 13:02 
GeneralRe: ListView issues Pin
Pete O'Hanlon6-Mar-10 9:41
mvePete O'Hanlon6-Mar-10 9:41 
AnswerRe: ListView issues Pin
Pete O'Hanlon6-Mar-10 10:22
mvePete O'Hanlon6-Mar-10 10:22 
John - you only need an ObservableCollection if you want to catch notification changes. In this case, you'd bind to the properties in exactly the same way you'd bind to an ObservableCollection. Here's a quick sample I whipped together for you:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BindToList
{
  /// <summary>
  /// Interaction logic for Window1.xaml
  /// </summary>
  public partial class Window1 : Window
  {
    private List<MyListItem> _list;
    public Window1()
    {
      InitializeComponent();

      _list = new List<MyListItem>();
      AddItem("John", "Simmons");
      AddItem("Pete", "O'Hanlon");
      AddItem("Clint", "Eastwood");

      foreach (MyListItem item in _list)
      {
        listBound.Items.Add((MyListItem)item);
      }

    }

    public List<MyListItem> MyList
    {
      get { return _list; }
      set { _list = value; }
    }

    public void AddItem(string forename, string surname)
    {
      _list.Add(new MyListItem { ID = _list.Count + 1, Forename = forename, Surname = surname });
    }
  }

  public class MyListItem
  {
    private int _id;

    public int ID
    {
      get { return _id; }
      set { _id = value; }
    }
    private string _forename;

    public string Forename
    {
      get { return _forename; }
      set { _forename = value; }
    }
    private string _surname;

    public string Surname
    {
      get { return _surname; }
      set { _surname = value; }
    }
  }
}
Now, here's the XAML that goes with this:
<Window x:Class="BindToList.Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="Window1" Height="300" Width="300">
  <Window.Resources>
    <DataTemplate x:Key="myListTemplate">
      <StackPanel Orientation="Horizontal">
        <TextBlock Text="{Binding ID}" />
        <TextBlock Text="{Binding Forename}" />
        <TextBlock Text="{Binding Surname}" />
      </StackPanel>
    </DataTemplate>
  </Window.Resources>
  <Grid>
    <ListBox x:Name="listBound" 
       ItemTemplate="{StaticResource myListTemplate}" 
       Width="200" />
  </Grid>
</Window>

"WPF has many lovers. It's a veritable porn star!" - Josh Smith

As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.


My blog | My articles | MoXAML PowerToys | Onyx



QuestionDisplay System.Windows.Forms.Form as child of Wpf Window Pin
abhinish6-Mar-10 1:01
abhinish6-Mar-10 1:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.