title: Loading XAML into a control at runtime and using the control's resources
body: <p>There's quite a few questions about loading XAML at runtime here,
  but as far I can tell this is not a duplicate.</p>
  
  <p>I'm loading XAML into a control at runtime:</p>
  
  <pre><code>&lt;ContentControl Content="{Binding Layout.View, Converter={StaticResource StringToXamlConverter}}"/&gt;
  </code></pre>
  
  <p>The converter is rather simple:</p>
  
  <pre><code>public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  {
      string xaml;
      if (value != null)
      {
          xaml = value.ToString();
      }
      else
      {
          xaml = Settings.Default.DefaultLayoutView;
      }
  
      var root = XamlReader.Parse(xaml);
      return root;
  }
  </code></pre>
  
  <p>Now, in the XAML that is being loaded, I need to make use of ValueConverters.
  The converters are defined as resources of the Window in to which the XAML is loaded. For example:</p>
  
  <pre><code>&lt;c:BooleanToVisibilityValueConverter x:Key="BooleanToVisibilityConverter"/&gt;
  </code></pre>
  
  <p>Of course, the XamlReader.Parse() method throws an exception if I try to use this resource as at the time of reading it is not available.</p>
  
  <pre><code>Visibility="{Binding Layout.TextItem1.IsEnabled, Converter={StaticResource BooleanToVisibilityConverter}}"
  </code></pre>
  
  <p>Is there a way to get around this?
  Perhaps a way to tell the XamlReader to ignore this?
  Or an alternative to ValueConverters that might work in this situation?</p>
  
  <p>Please note, using a DynamicResource does not work either. They cannot be used for ValueConverters.</p>