Preventing XAML Reformatting

Dec 8, 2010 at 6:45 PM

Hi, I am trying to change the code so that my xaml code stays exactly the same except for the binding to my resource file. 

Example 1:
I have 1 xmlns per line, after running the WPF Localization Addin, it would put 2 xmlns per line.

Example 2:
When I place my attributes for a control on separate lines indented after the control type. But after running the tool, the indentation would be shift to the left for the 2nd, 3rd, ... rows.

Could you give me some advice on how to prevent this? I turned off xaml reformating, but that did not have an effect.

Coordinator
Dec 9, 2010 at 5:37 AM

Hi!

I also tried to do this, but unfortunately have not found easy solution.

Available XML readers don't preserve whitespaces inside opening element tags - i.e. between attributes.

If turn off xaml reformating, it will preserve whitespaces between element tags, but again, not inside tags.

That's why I've added xaml reformating, which worked better for me. I even used it later without extracting resources, to have "well-formatted" xamls.

The solution could be to implement custom XML parser, or pair of XmlReader/XmlWriter, which will preserve whitespaces between attributes. (As an idea, we can present whitespaces as attributes with special name during reading and in DOM, and then recognize them during writing. One more idea - to use XAMLSerializer, which I believe VS uses, but this will be much more complex.)

To get idea how xaml reformatting work, you can look at class PrettyXmlWriter. E.g. you can adjust serializing of first element to get 1 xmlns per line or adjust indentation. (Perhaps there is a bug with indentation there?)

Regards!

Coordinator
May 13, 2011 at 1:43 PM

Hi!

I've discovered technic, used by MS in UpdateUid tasks, which allows to preserve XAML formatting.

Please vote for the workitem http://wpflocalizeaddin.codeplex.com/workitem/681 so I'll see if this is interesting for you!

Regards,

Konstantin