1

Hi I'd like to inquire on how i can load a WPF Xaml into code so that I can change the values of the attributes of some XAML elements and output it by creating another XAML files. This is so that I can output the same file with values dynamically input by the user.

the XamlReader.Load() method cannot be used; it will throw an exception (because they are unable to recognise Window as the root element). I'm using VS2013 and C#.

Shell
  • 6,818
  • 11
  • 39
  • 70
  • 2
    Is there a particular reason you can't do this with binding rather than by modifying the xaml? – N_A Jun 06 '14 at 03:25
  • 1
    Actually I am trying to create multiple copies of the same projects, but the margins of several stuff (as well as other attribute values) are to be changed according to user preference, so the idea of a "tool" like program that will furnish details that are not to be packaged in the project. – user3713589 Jun 06 '14 at 05:50
  • 1
    I think you would have an easier time of simply storing those preferences in a config file and then binding the xaml to properties exposing those values. What you're trying to do sounds like a lot more work and a lot less maintainable. – N_A Jun 06 '14 at 14:12

1 Answers1

2

XamlReader is the answer... just need to be aware of the trick to using it. See the answer to this question: Can I use XamlReader.Load or InitializeFromXaml from a WPF Window, for the Window definition?

Community
  • 1
  • 1
Robert Levy
  • 28,747
  • 6
  • 62
  • 94