Friday, August 20, 2010

Visual Studio find and replace with regular expressions totally sucks.

The syntax for regular expressions in Visual studio's find and replace option are incredibly convoluted.

I wanted to replace all instances of width in a style sheet with something that was variable based.

so width:75px; would become width:@(width=75)px;

This syntax is using the new Razor view engine and the result is we set a local variable and render it to the page in a nice terse expression. Combined with:

left:@(leftStart+width)px;

we now have the beginning of a nice sliced row of images. Where all the things on a particular row would incrementally build, and then on the next row, I can reset leftStart.

This was the syntax for finding all lines of an html document and capturing the width:
width\:{[0-9]+}

And the syntax for the replacement?
width\:\@(width=\1)

I understand that c# syntax uses a ton of the same conflicting symbols, but... could you guys make something like rexexpal so that we can iteratively solve for the expressions we need?

Wednesday, August 18, 2010

WPF DataGrid Row-level styling

It took me a very long time to figure out how to do this. The following code takes a WPF (and probably silverlight) datagrid and changes the row foreground color based on a single property in that row.

<DataGrid AutoGenerateColumns="True"  Name="dgProjects" >
    <DataGrid.RowStyle>
                <Style TargetType="DataGridRow">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Path=HasProblems}" Value="True">
                            <Setter Property="Foreground" Value="Red"/>
                        DataTrigger>
                    Style.Triggers>
                   
                Style>
            DataGrid.RowStyle>
DataGrid>

Monday, August 16, 2010

Vs Add-in solution explorer context menus with a little MEF

My first MEF success. I wrote a visual studio add-in context menu for solution explorer where you can right click a project (or solution file for all projects) so that it:



  • reads the project file checking several problem areas 
    • hint paths
    • copy local
    • pre/post build events
    • target framework version
  • then makes a backup copy
  • cleans those local customizations
  • invokes msbuild to make sure it still builds
  • brings up the Source control commit dialog
  • restores your local customizations that we don't want in the source.
I used MEF so that the UI was not hard coded into the add-in. It  was amazingly simple. While I was developing a solution someone was nice enough to post on stackoverflow telling me you can't hydrate static properties. Which I did.