Binding Dynamically Loaded XAML to Content Property of ContentControl RRS feed

  • General discussion

  • What I am trying to do is load xaml either from a database or a text file on the web server and use a xaml reader to parse it into an object that can be placed into a content control.

    I have found several great articles on how to do this but want to use databinding and I was wondering if it is possible to set the content property of a content control to a xaml object using databinding and a value converter.

    Something like this

    <ContentControl Content="{Binding Converter={StaticResource XamlConverter}, Path=IconXaml}

    The value converter takes a string and uses a xaml reader internally to parse it it turn it into an object that the converter passed back - like this

    <!-- converter -->
    public class XamlToObjectConverter : IValueConverter

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      return System.Windows.Markup.XamlReader.Load(value.ToString());
      return "error loading xaml";

    I wanted to make sure this is even possible before I modify the db to store the xaml and try to data bind it.



    Wednesday, April 8, 2009 12:12 AM