Wednesday, March 28, 2007


The easiest sample how you can use WCF togehter with IIS can be found at

Monday, March 26, 2007

Object binding with WPF

It took me some time to find a good sample of doing object binding with WPF. I decided to publish my sample.

I created a class called patient.

public class Patient
private int _id;
private string _name;
private string _picture;

public string Picture
get { return _picture; }
set { _picture = value; }

public Patient(int id, string name , string picture)
_id = id;
_name = name;
_picture = Picture;

public string Name
get { return _name; }
set { _name = value; }
public int ID
get { return _id; }
set { _id = value; }

This patient class is filled with data by an engine class. This engine class is called PatientEngine.

public class PatientsEngine
public static List GetPatients()
List pList = new List();
Patient p1 = new Patient(1, "Jack", "Images/Jack.png");
Patient p2 = new Patient(2, "Jim", "Images/Jim.png");
Patient p3 = new Patient(3, "Johny", "Images/Johny.png");
return pList;

This class has a static method to fill the generic list of patients.

To call the engine you need to

  1. Create a new windows XAML application
  2. Open the window1 file
  3. Add in the window tag the namespace declaration where your engine is located, in my case in "WindowsApplication4" do this by adding this line.
  4. Add the ObjectDataProvider in the element
    <objectdataprovider key="patients" objecttype="{x:Type src:PatientsEngine}" methodname="GetPatients"></objectdataprovider>
  5. Create a data template

    <DataTemplate x:Key="patientFormating" DataType="Patient">
    <StackPanel Orientation="Vertical">
    <Binding Path="Name" />
    <Binding Path="Picture" />
  6. Add the code to display a listview in a DockPanel

    <DockPanel DataContext="{Binding Source={StaticResource patients}}" Grid.Column="0" Grid.Row="0">
    <ListView x:Name="listView1" ItemsSource="{Binding }" ItemTemplate="{DynamicResource patientFormating}" IsSynchronizedWithCurrentItem="True" DockPanel.Dock="Left" />
    </DockPanel />