Bind to ObservableCollection and ItemsSource : ObservableCollection « Windows Presentation Foundation « C# / CSharp Tutorial

<Window x:Class="DataTriggerSample.Window1"
  Title="DataTriggerSample" Height="300" Width="300">
    <c:People x:Key="PeopleData"/>

    <Style TargetType="{x:Type ListBoxItem}">
        <DataTrigger Binding="{Binding Path=Name}" Value="A">
          <Setter Property="Background" Value="Yellow" />
            <Condition Binding="{Binding Path=Name}" Value="S" />
            <Setter Property="Background" Value="LightGreen" />

    <DataTemplate DataType="{x:Type c:Person}">
      <Canvas Width="260" Height="20">
        <TextBlock FontSize="12" Width="130" Canvas.Left="0" Text="{Binding Path=Name}"/>

    <TextBlock FontSize="18" Margin="5" FontWeight="Bold"
      HorizontalAlignment="Center">Data Trigger Sample</TextBlock>
    <ListBox Width="250" HorizontalAlignment="Center" Background="White"
      ItemsSource="{Binding Source={StaticResource PeopleData}}"/>


using System;
using System.Collections.Generic;
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.Shapes;
using System.Collections.ObjectModel;

namespace DataTriggerSample
    public partial class Window1 : System.Windows.Window
        public Window1()

    public class Person
        private string _name;
        public string Name
            get { return _name; }
            set { _name = value; }

        public Person(string name)
            this._name = name;

    public class People : ObservableCollection<Person>
        public People()
            Add(new Person("A"));
            Add(new Person("B"));
            Add(new Person("C"));

WPF Bind To Observable Collection And Items Source

24.148.1.Use ObservableCollection as ResourceUse ObservableCollection as Resource
24.148.2.Bind to ObservableCollectionBind to ObservableCollection
24.148.3.Create a ListView control that uses a GridView view mode to display the contents of an ObservableCollection<(Of <(T>)>).Create a ListView control that uses a GridView view mode to display the contents of an ObservableCollection<(Of <(T>)>).
24.148.4.Bind to ObservableCollection and ItemsSourceBind to ObservableCollection and ItemsSource
24.148.5.Apply Custom Sorting Logic to a CollectionApply Custom Sorting Logic to a Collection