title: Set default value in XAML if binding is null
body: <p><strong>EDIT</strong></p>
  
  <p>This is no duplicate of a fallback for string null values. I'm asking for a fallback for a complex type.</p>
  
  <p><strong>Original question</strong></p>
  
  <p>This is a followup question to a question I've asked yesterday:</p>
  
  <p><a href="https://stackoverflow.com/questions/44805620/bind-wpf-command-to-viewmodel-property-in-c-sharp-xaml">Bind WPF Command to ViewModel property in C# XAML</a></p>
  
  <p>The core part of the accepted answer to me was this:</p>
  
  <pre><code>&lt;Window.Resources&gt;
      &lt;DataTemplate DataType="{x:Type local:SettingsPathSelectorViewModel}"&gt;
          &lt;StackPanel Orientation="Horizontal"&gt;
              &lt;TextBox Text="{Binding SettingsPath}" /&gt;
              &lt;Button 
                  Content="..." 
                  Command="{Binding OpenFile}" 
                  HorizontalAlignment="Left" 
                  MinWidth="40" 
                  Margin="4,0,0,0" 
                  /&gt;
          &lt;/StackPanel&gt;
      &lt;/DataTemplate&gt;
  &lt;/Window.Resources&gt;
  &lt;Grid&gt;
      &lt;StackPanel Orientation="Vertical"&gt;
          &lt;Label&gt;First Path&lt;/Label&gt;
          &lt;ContentControl Content="{Binding FirstPath}" /&gt;
      &lt;/StackPanel&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>A <code>DataTemplate</code>is created for a custom type and then a <code>ContentControl</code> is bound to a property of that type.</p>
  
  <p>The problem is now, that the property (<code>FirstPath</code> in the example) could be <code>null</code> and no UI elements are rendered. How could I accomplish to render the controls from the <code>DataTemplate</code> even if the property is <code>null</code></p>
  
  <p>As Evk suggested I've implemented a Converter:</p>
  
  <pre><code>public class PathSelectorConverter : IValueConverter
  {
      public object Convert(object o, Type type, object parameter, CultureInfo culture)
      {
          return o ?? new PathSelector();
      }
      public object ConvertBack(object o, Type type, object parameter, CultureInfo culture)
      {
          return o ?? new PathSelector();
      }
  }
  </code></pre>
  
  <p>I've added an instance of the converter a resource in my window:</p>
  
  <pre><code>&lt;view:PathSelectorConverter x:Key="pathSelectorConverter"/&gt;
  </code></pre>
  
  <p>And added it in the binding to the property:</p>
  
  <p></p>
  
  <p>But the converter is only called if the value is not null</p>