title: WPF pass data-generated parameter to Method through XAML
body: <p>I am writing a "problem resolver" for a despatch app.</p>
  
  <p>The despatch app prints labels using a piece of software supplied by the UKs Royal Mail postal service. The software ensures that the addresses on the labels are "correct" as per the Royal mail's database of valid addresses, it renders a trackable code in alphanumeric and barcoded format and it automatically bills our company for secure mail sent via the system without having to do very much paperwork.</p>
  
  <p>It's the latter "feature" that causes a problem. If a label is printed and not required because a) the customer is in a foreign country we do not mail to or b) two orders are for the same person at the same address we want to either not print a label in the former case or print one of two in the latter.</p>
  
  <p>The country thing is easy. If a customer really is in another country you just don't include it in the list of customers sent to the Royal Mail app for processing (but some customers get handy with the mouse wheel and end up pretending to be from the United Arab Emirates when they're really from Banbury) the "Duplicate Postcode" issue, however, is much more troublesome.</p>
  
  <p>In the UK two people will have the same postcode if they live on the same street. So obviously if two people on the same street want something you must print two labels. Similarly if two brothers live at the same address we want to ensure that both brothers receive their individual mail items (in this case the postcode, house number and surname will all match). However if two orders exist at the same address for Mr AN Other then MR Other should only require one label and his despatches can be combined.</p>
  
  <p>Believe it or not we do have cases where Mr AN Other orders twice and Mr Someother-Dude in the same street orders something as well. In this case the problem resolver rather than just needing to tweak a predefined field to some other known value needs to let the user decide how many labels to print out.</p>
  
  <p>In order to model this scenario in a UI I have created a listbox with a dynamic datatemplate that either allows people to straight include/not include the country problem people but in the case of Postcode problems it presents a horizontally aligned listbox which should include all the orders that have the same postcode.</p>
  
  <p>So simply this is as far as I have got with this:</p>
  
  <pre><code>   &lt;DataTemplate x:Key="postcodeTemplate"&gt;
              &lt;Grid&gt;
                  &lt;Grid.RowDefinitions&gt;
                      &lt;RowDefinition&gt;&lt;/RowDefinition&gt;
                      &lt;RowDefinition&gt;&lt;/RowDefinition&gt;
                  &lt;/Grid.RowDefinitions&gt;
                  &lt;Grid.ColumnDefinitions&gt;
                      &lt;ColumnDefinition&gt;&lt;/ColumnDefinition&gt;
                      &lt;ColumnDefinition&gt;&lt;/ColumnDefinition&gt;
                  &lt;/Grid.ColumnDefinitions&gt;
                  &lt;Label Grid.Row="0"&gt;This Order's Postcode matches the postcode of another order. Choose what to do.&lt;/Label&gt;
                  &lt;RadioButton&gt;Send all.&lt;/RadioButton&gt;
                  &lt;RadioButton&gt;Send this one only.&lt;/RadioButton&gt;
                  &lt;ListBox Grid.Row="0" Grid.Column="1" Grid.RowSpan="2"&gt;
                      &lt;ListBox.ItemsPanel&gt;
                          &lt;ItemsPanelTemplate&gt;
                              &lt;VirtualizingStackPanel
                                  Orientation="Horizontal"
                                  IsItemsHost="true" /&gt;
                          &lt;/ItemsPanelTemplate&gt;
                      &lt;/ListBox.ItemsPanel&gt;
                  &lt;/ListBox&gt;
              &lt;/Grid&gt;
          &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>How do I pass the postcode of the current customer (contained in an Observable Collection) through to a method which will return a list of customers at the same postcode which will then display in the final listbox?</p>