title: How to handle bindings when the source object may not have the given property?
body: <p>I have two classes with different properties, but both inherit some other base class:</p>
  <pre><code>public class BaseClass { }
  
  public class ClassA : BaseClass
  {
      public string PropertyA { get; set; }
  }
  
  public class ClassB : BaseClass
  {
      public string PropertyB { get; set; }
  }
  </code></pre>
  <p>Code-behind:</p>
  <pre><code>public ObservableCollection&lt;BaseClass&gt; Items { get; set; }
  
  public MainWindow()
  {
      Items = new ObservableCollection&lt;BaseClass&gt;
          {
              new ClassA {PropertyA = &quot;A&quot;},
              new ClassB {PropertyB = &quot;B&quot;}
          };
  }
  </code></pre>
  <p>And my XAML looks like this:</p>
  <pre><code>&lt;ListView ItemsSource=&quot;{Binding Items}&quot;&gt;
      &lt;ListView.View&gt;
          &lt;GridView&gt;
              &lt;GridViewColumn DisplayMemberBinding=&quot;{Binding PropertyA, FallbackValue=''}&quot;/&gt;
              &lt;GridViewColumn DisplayMemberBinding=&quot;{Binding PropertyB, FallbackValue={x:Null}}&quot;/&gt;
          &lt;/GridView&gt;
      &lt;/ListView.View&gt;
  &lt;/ListView&gt;
  </code></pre>
  <p>When running in debug mode, the output window shows this:</p>
  <blockquote>
  <p>System.Windows.Data Warning: 40 : BindingExpression path error: 'PropertyB' property not found on 'object' ''ClassA' (HashCode=66437409)'. BindingExpression:Path=PropertyB; DataItem='ClassA' (HashCode=66437409); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')</p>
  <p>System.Windows.Data Warning: 40 : BindingExpression path error: 'PropertyA' property not found on 'object' ''ClassB' (HashCode=2764078)'. BindingExpression:Path=PropertyA; DataItem='ClassB' (HashCode=2764078); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')</p>
  </blockquote>
  <p>Is there a better way of handling bindings like these? Are there any performance implications, and is it better to use FallbackValue='' or FallbackValue={x:Null}?</p>