title: Use a default value when binding cannot be evaluated because of a null value
body: <p>is there a way to assign a <strong>special value</strong> when a <strong>binding</strong> cannot be evaluated because of a <strong>null value</strong> in the <strong>property path</strong> ?</p>
  
  <p>For instance if I have a property <strong>Name</strong> in a class <strong>Customer</strong> and a binding like this :</p>
  
  <pre><code>{Binding CurrentCustomer.Name}
  </code></pre>
  
  <p>When <strong>CurrentCustomer</strong> is null I'd like the binding to produce the string "---".</p>
  
  <p>"TargetNullValue" and "FallbackValue" don't seem to do the trick.</p>
  
  <p>Thanks in advance for your help.</p>
  
  <p><strong>EDIT</strong> :</p>
  
  <p>In fact what I'm trying to do is substituting a <strong>new source value</strong> in place of the true when it is not available.
  The real scenario is the following :</p>
  
  <p>a bool value is used to determine the visibility of a control, but when this value is not attainable I'd like to replace it with "false".</p>
  
  <p>Here is an illustration that perfectly mimics my real use-case :</p>
  
  <p>MainPage.xaml.cs :</p>
  
  <pre><code>using System;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Data;
  
  namespace TestSilverlightBindingDefaultValue
  {
      public class BoolToVisibilityConverter : IValueConverter
      {
          #region IValueConverter Members
  
          public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
          {
              return (bool)value ? Visibility.Visible : Visibility.Collapsed;
          }
  
          public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
          {
              throw new NotImplementedException();
          }
  
          #endregion
      }
  
      public class Customer
      {
          public bool HasACar
          {
              get;
              set;
          }
      }
  
      public partial class MainPage : UserControl
      {
          public static readonly DependencyProperty CurrentCustomerProperty =
              DependencyProperty.Register("CurrentCustomer", typeof(Customer), typeof(MainPage), null);
  
          public Customer CurrentCustomer
          {
              get { return this.GetValue(CurrentCustomerProperty) as Customer; }
              set { this.SetValue(CurrentCustomerProperty, value); }
          }
  
          public MainPage()
          {
              InitializeComponent();
  
              this.CurrentCustomer = null;
  
              this.DataContext = this;
          }
      }
  }
  </code></pre>
  
  <p>MainPage.xaml :</p>
  
  <pre><code>&lt;UserControl x:Class="TestSilverlightBindingDefaultValue.MainPage"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:local="clr-namespace:TestSilverlightBindingDefaultValue"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  mc:Ignorable="d"
  d:DesignHeight="300" d:DesignWidth="400"&gt;
  &lt;UserControl.Resources&gt;
      &lt;local:BoolToVisibilityConverter x:Key="boolToVisibilityConverter" /&gt;
  &lt;/UserControl.Resources&gt;
      &lt;StackPanel x:Name="LayoutRoot" Background="White"&gt;
      &lt;TextBlock Text="You have a car"  Visibility="{Binding CurrentCustomer.HasACar,Converter={StaticResource boolToVisibilityConverter}}" /&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>FallbackValue</strong> is not the solution because it would only change the generated value and not the source value.</p>
  
  <p><em>Abe Heidebrecht</em> has provided the perfect solution for <strong>WPF</strong> with <strong>PriorityBinding</strong> but it does not exist in <strong>Silverlight</strong>.</p>
  
  <p><strong>FINAL EDIT</strong> :
  The second solution of <em>Abe Heidebrecht</em>, ie wrapping in another element, is working perfectly.</p>