title: WPF Binding Programmatically
body: <p>I am attempting to convert this xaml binding to it's C# counterpart for various reasons:</p>
  
  <pre><code>&lt;ListView x:Name="eventListView" Grid.Column="0" Grid.Row="1" Background="LightGray" BorderThickness="0"&gt;
      &lt;local:EventCell x:Name="cell" Width="{Binding ActualWidth, Converter={StaticResource ListViewWidthConverter}, ElementName=eventListView, Mode=OneWay}"/&gt;
  &lt;/ListView&gt;
  </code></pre>
  
  <p>I've read a lot of questions already that had similar problems and came up with this code:</p>
  
  <pre><code>Binding b = new Binding();
  b.Source = eventListView;
  b.Path = new PropertyPath(cell.Width);
  b.Converter = new ListViewWidthConverter();
  b.Mode = BindingMode.OneWay;
  cell.SetBinding(ListView.ActualWidthProperty, b);
  </code></pre>
  
  <p>But the C# code won't compile, I am pretty lost as to why.</p>