How do I implement design-time checking for XAML that leads to compilation errors?

How to enforce that developers writing XAML in Visual Studio must follow certain standards and checks must be performed and if there are compile-time errors.

For example, make sure that all data binding expressions (some of them are real) are written correctly according to the "custom validation" that I would like to implement at design time. For example,

<TextBox Text="{Binding Source={StaticResource CALCULATED}, Converter={StaticResource XPathConverter}, ConverterParameter=@FIRSTNAME_STRING, XPath=@FIRSTNAME}"/>

      

In the above example, if the binding expression in the Text property is not in this format , there must be a compilation error .

Is there a way to do this?

0


source to share


2 answers


Sorry, the servicing XAML cannot be extended this way. The best way to do this today is to create a build task. I think you can hook it up to the MarkupCompilePass1DependsOn target and it will be called automatically when the user saves or modifies the XAML file. You will still have to scan the file redundantly from us, but you don't have to wait for the actual build to make this work. This is a direct quote from one of the Microsoft architects currently working on WPF designers.



0


source


There is no built-in way to do this. The best way to get this result is to run a custom tool on the input. This will take a lot of work on your part because it will involve parsing the file yourself, but you should be able to get this script to work.

Sample site for creating a custom generator



http://www.drewnoakes.com/snippets/WritingACustomCodeGeneratorToolForVisualStudio/

+2


source







All Articles