简体   繁体   中英

How do you use stylecop with .xaml files

I have been tasked with utilizing stylecop on.xaml files. Does anyone have a good place to start looking for the best way to accomplish this task. I have drifted around the internet and have yet to find a good solution. Our development environment is VS 2010 WPF application. Thank you for your help.

StyleCop is a source analysis tool to increase the readability of it. Visual Studio itself would be a good place to start. When you start writing xaml using VS it automatically indents code.

Here is an example

<Window x:Class="WpfApplication3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button Content="Hi" />
</Grid>
</Window>

This is what is expected (I think)

<Window x:Class="WpfApplication3.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Button Content="Hi" />
    </Grid>
</Window>

The Microsoft Xaml Toolkit has Fxcop integration you might find useful.

blog posting: http://blogs.msdn.com/b/wpf/archive/2010/07/28/microsoft-xaml-toolkit-ctp-july-2010-fxcop-integration.aspx

downloads: http://archive.msdn.microsoft.com/XAML

As per http://archive.msdn.microsoft.com/sourceanalysis , StyleCop only analyzes C# source code - XAML is a completely different language. If your boss or manager tasked you with using StyleCop on the .xaml files - what they probably meant (and you should double check with them rather than take my word for it), is to analyse the associated xaml.cs files. Every xaml file is a partial class - one part of the class is the XAML (which gets translated to an automatic xaml.designer.cs file which you cannot and should not mess with) - and the other part of the class (often called the codebehind) is the .xaml.cs . This document is one you can use StyleCop on, although some of it's rules may be confused by the fact that it's being run on only one half of a partial class.

That's the best you can hope to accomplish.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM