Friday, March 30, 2012

Label ContentStringFormat

Again this morning struggled with something I knew I had struggled with before this time I am in WPF XAML trying to set a StringFormat on my binding to get it formatted as a 2 decimal:

<Label Content="{Binding SelectedObject.DoubleNumber, StringFormat=N2}"/>

Running my view it is not showing me what I want to see; in this case showing 17.877651246, then I suddenly remembered that the Label control has its own way of dealing with StringFormat with the ContentStringFormat property:

<Label ContentStringFormat="N2" Content="{Binding SelectedObject.DoubleNumber}" />

The view is giving me 17.88 awesome!
I hope I remember this now actually makes a bit sense; I am setting the Content so setting the  Content => StringFormat .. aah

Thursday, March 29, 2012

Find and Replace using regular expressions

Decided today to take my Find and Replace up one notch:
I got this code:
var parameters = new
{
        labSoilAnalysis.ID,
        labSoilAnalysis.Year,
        labSoilAnalysis.Season,
        labSoilAnalysis.RegionID,
        labSoilAnalysis.FieldID
};


that I want to change to:
var parameters = new
{
        ID =  labSoilAnalysis.ID,
        Year = labSoilAnalysis.Year,
        Season = labSoilAnalysis.Season,
        RegionID = labSoilAnalysis.RegionID,
        FieldID = labSoilAnalysis.FieldID
};

Using regular expressions I ended up using:

The expression in the find box: {labSoilAnalysis}{.}{.+[^,]} is 3 tag expressions that is each assigned a number that I use in the Replace box, to reorder the code.

I know that it can be done in a beter way but me being a newbie to regex… maybe some of the big guns can help to make it beter, please post a comment with your take!