title: WPF Objectbinding of Collection
body: <p>I have a taskbar-application developed with WPF, where I just can't figure out how to bind my collection of objects with Objectbinding to a TrayPopUp.</p>
  
  <p>Here's my collection class. It is created on startup and filled with objects by deserializing a xmlfile (with fillCollectionFromXml-method):</p>
  
  <pre><code>public class OrdreCollection
  {
      // Fields
      private ObservableCollection&lt;Ordre&gt; _ordreList = new ObservableCollection&lt;Ordre&gt;();
  
  
      // Properties
      public ObservableCollection&lt;Ordre&gt; OrdreList
      {
          get
          {
              if (_ordreList == null)
              {
                  return new ObservableCollection&lt;Ordre&gt;();
              }
              return _ordreList;
          }
  
          set
          {
              _ordreList = value;
          }
      }
  
  
      //Methods
  
      public void fillCollectionFromXml(String filepath)
      {            
          XmlSerializer xs = new XmlSerializer(typeof(ObservableCollection&lt;Ordre&gt;));
          using (StreamReader rd = new StreamReader(filepath))
          {
              OrdreList = xs.Deserialize(rd) as ObservableCollection&lt;Ordre&gt;;
          }
      }
  
      public void createXmlFromCollection(OrdreCollection oCol, String filepath)
      {
          XmlSerializer xs = new XmlSerializer(typeof(ObservableCollection&lt;Ordre&gt;));
          using (StreamWriter wr = new StreamWriter(filepath))
          {
              xs.Serialize(wr, OrdreList);
          }
      }
  
      //public OrdreCollection getOrdrer(String filepath)
      //{
      //    OrdreCollection Ordrer = new OrdreCollection();
      //    Ordrer.fillCollectionFromXml("@../../Data/Ordrer.xml");
  
      //    return Ordrer;
      //}
  }
  }
  </code></pre>
  
  <p>Base-classes:</p>
  
  <pre><code>[Serializable]
  public class Ordre : INotifyPropertyChanged
  {
      // INotifyPropertyChanged Member
      public event PropertyChangedEventHandler PropertyChanged;
      void Notify(string propName) {
          if (PropertyChanged != null)
              PropertyChanged(this, new PropertyChangedEventArgs(propName));
      }
  
      // Fields
      private DateTime ordreDato = DateTime.Today;
      private int ordreReference = 561978;
      private String bestiltAf;
      private List&lt;OrdreItem&gt; ordreItem;
  
      //Constructors
  
      public Ordre() { }
  
      public Ordre(DateTime ordredato, int ordrereference, String bestiltAf, List&lt;OrdreItem&gt; ordreItem)
      {
          this.Ordredato = ordredato;
          this.Ordrereference = ordrereference;
          this.BestiltAf = bestiltAf;
          this.OrdreItem = ordreItem;
      }
  
  
      //Properties
  
      public DateTime Ordredato
      {
          get { return ordreDato; }
          set { 
              ordreDato = value;
              Notify("OrdreDato");
          }
      }
  
      public int Ordrereference
      {
          get { return ordreReference; }
          set { 
              ordreReference = value;
              Notify("Ordrereference");
          }
      }
  
      public String BestiltAf
      {
          get { return bestiltAf; }
          set { 
              bestiltAf = value;
              Notify("BestiltAf");
          }
      }
  
      public List&lt;OrdreItem&gt; OrdreItem
      {
          get { return ordreItem; }
          set {
              ordreItem = value;
              Notify("OrdreItem");
          }
      }
  
  
      //Methods
  
      public void addItem(OrdreItem item)
      {
          OrdreItem.Add(item);
      }
  }
  
  [Serializable]
  public class OrdreItem : INotifyPropertyChanged
  {
      // INotifyPropertyChanged Member
      public event PropertyChangedEventHandler PropertyChanged;
      void Notify(string propName)
      {
          if (PropertyChanged != null)
              PropertyChanged(this, new PropertyChangedEventArgs(propName));
      }
  
      // Fields
      private String produktKode;
      private String produktNavn;
      private DateTime kalibreringsDato;
      private DateTime leveringsDato;
      private int antal;
  
      // Constructors
      public OrdreItem() { }
      public OrdreItem(String produktKode, String produktNavn, DateTime kalibreringsDato, DateTime leveringsDato, int antal)
      {
          this.produktKode = produktKode;
          this.produktNavn = produktNavn;
          this.kalibreringsDato = kalibreringsDato;
          this.leveringsDato = leveringsDato;
          this.antal = antal;
      }
  
      //Properties
      public String ProduktKode
      {
          get { return produktKode; }
          set {
              produktKode = value;
              Notify("ProduktKode");
          }
      }
  
      public String ProduktNavn
      {
          get { return produktNavn; }
          set {
              produktNavn = value;
              Notify("ProduktNavn");
          }
      }
  
      public DateTime KalibreringsDato
      {
          get { return kalibreringsDato; }
          set { 
              kalibreringsDato = value;
              Notify("KalibreringsDato");
          }
      }
  
      public DateTime LeveringsDato
      {
          get { return leveringsDato; }
          set { 
              leveringsDato = value;
              Notify("LeveringsDato");
          }
      }
  
      public int Antal
      {
          get { return antal; }
          set {
              antal = value;
              Notify("Antal");
          }
      }
  }
  </code></pre>
  
  <p>Here's my XAML:</p>
  
  <pre><code>&lt;ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      xmlns:tb="clr-namespace:Hardcodet.Wpf.TaskbarNotification;assembly=Hardcodet.Wpf.TaskbarNotification"
                      xmlns:local="clr-namespace:WpfApplication1.Models"
                      x:Class="WpfApplication1.Resources"
                      x:ClassModifier="public"
                      &gt;
      &lt;!-- Globaly declared OrdreCollection. Contains a list of orders.--&gt;
      &lt;local:OrdreCollection x:Key="OrdreList"&gt;&lt;/local:OrdreCollection&gt;
  
      &lt;!-- Globally declared notify icon --&gt;
      &lt;tb:TaskbarIcon x:Key="MyNotifyIcon" 
                      IconSource="/Icons/ge256x256new.ico" 
                      ToolTipText="GE Ordre Management"
                      PopupActivation="LeftOrDoubleClick"
                      DataContext=" "
                      &gt;
      &lt;!--
      We can use arbitrary UI elements as ToolTips.
      Let's use a semi-transparent border.
      --&gt;
  
          &lt;!-- Set a simple popup  --&gt;
          &lt;tb:TaskbarIcon.TrayPopup&gt;
              &lt;Border
                  Background="White"
                  BorderBrush="Orange"
                  BorderThickness="2"
                  CornerRadius="4" Margin="0" Padding="10"&gt;
                  &lt;GroupBox Header="Bestillinger" Height="Auto" Name="BestillingGroupBox" Width="445" HorizontalAlignment="Left" VerticalAlignment="Top" Padding="10"&gt;
                      &lt;Grid&gt;
                          &lt;!--&lt;ListBox ItemsSource="{Binding}" DisplayMemberPath="ordreDato"/&gt;--&gt;
                          &lt;ListView IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding OrdreList}"&gt;
                              &lt;ListView.View&gt;
                                  &lt;GridView&gt;
                                      &lt;GridViewColumn Header="Ordredato" DisplayMemberBinding="{Binding Path=Ordredato}" /&gt;
                                      &lt;GridViewColumn Header="Navn" DisplayMemberBinding="{Binding Path=BestiltAf}" /&gt;
                                      &lt;GridViewColumn Header="Ordrenummer" DisplayMemberBinding="{Binding Path=Ordrereference}" /&gt;
                                  &lt;/GridView&gt;
                              &lt;/ListView.View&gt;
                          &lt;/ListView&gt;
                      &lt;/Grid&gt;
                      &lt;!--&lt;Grid&gt;
                          &lt;Grid.DataContext&gt;
                              &lt;XmlDataProvider Source="@../../Data/employees.xml" /&gt;
                          &lt;/Grid.DataContext&gt;
                          &lt;Grid.Resources&gt;
                              &lt;HierarchicalDataTemplate x:Key="OrdreTemplate" DataType="Ordre"&gt;
                                  &lt;Border Background="White" BorderBrush="Orange" BorderThickness="2" CornerRadius="4" Margin="0" Padding="10" Width="400"&gt;
                                  &lt;TextBlock&gt;
                                  &lt;TextBlock FontWeight="bold"&gt;Antal: &lt;/TextBlock&gt;
                                  &lt;TextBlock Text="{Binding XPath=Antal}" /&gt;
                                  &lt;TextBlock FontWeight="bold"&gt;Produkt: &lt;/TextBlock&gt;
                                  &lt;TextBlock Text="{Binding XPath=Produkt}" /&gt;
                                  &lt;LineBreak&gt;&lt;/LineBreak&gt;
                                  &lt;TextBlock FontWeight="bold"&gt;Dato:&lt;/TextBlock&gt;
                                  &lt;TextBlock Text="{Binding XPath=Dato}" /&gt;
                                  &lt;LineBreak&gt;&lt;/LineBreak&gt;
                                  &lt;TextBlock FontWeight="bold"&gt;Bestilt af:&lt;/TextBlock&gt;
                                  &lt;TextBlock Text="{Binding XPath=BestiltAf}" /&gt;
                                  &lt;LineBreak&gt;&lt;/LineBreak&gt;
                                  &lt;TextBlock FontWeight="bold"&gt;Leveringsdato:&lt;/TextBlock&gt;
                                  &lt;TextBlock Text="{Binding XPath=TilLevering}" /&gt;
                                  &lt;LineBreak&gt;&lt;/LineBreak&gt;
                                  &lt;TextBlock FontWeight="bold"&gt;Ordrenr.:&lt;/TextBlock&gt;
                                  &lt;TextBlock Text="{Binding XPath=OrdreNr}" /&gt;                            
                              &lt;/TextBlock&gt;
                                  &lt;/Border&gt;
                              &lt;/HierarchicalDataTemplate&gt;
                          &lt;/Grid.Resources&gt;
  
                          &lt;ListBox                         
                          Name="treeView" 
                          ItemsSource="{Binding Path=.,XPath=/Ordrer/Ordre}"
                          ItemTemplate="{StaticResource OrdreTemplate}" Background="white"
                          BorderBrush="Black"
                          BorderThickness="1"
                          Padding="4" /&gt;
                      &lt;/Grid&gt;--&gt;
                  &lt;/GroupBox&gt;
              &lt;/Border&gt;
          &lt;/tb:TaskbarIcon.TrayPopup&gt;
      &lt;/tb:TaskbarIcon&gt;
  &lt;/ResourceDictionary&gt;
  </code></pre>
  
  <p>The problem is with TrayPopup. This I would like to show the values of all Orders in my OrderCollecion in a listview/listBox. I hope my question is understandable and that my code isn't too messy. I can make it work when I fill a listbox with a XmlDataProvider, but not with a ObjectdataProvider or directly from a collection.</p>