Terje Isaksen Developer blog

2009-11-24 (Tuesday)

Numeric to string

Filed under: Developing — Terje Isaksen @ 17:25
Tags: ,

Binding a textbox to a numeric source and formatting it is done by

<TextBox Text="{Binding Path=Fieldname, StringFormat=formatstring}"/>

where “formatstring” can for example be any of following:

Fn – fixed point number  – where n= number of decimals
Pn – percentage (value is multiplied with 100 and displayed with a %-symbol) – where n = number of decimals
Dn – integer – where n= number of digits
Nn – number with decimals and group separators, where n=number of decimals
Xn – hexadecimal integer – where n= number of digits

It can also be a string of custom numeric format characters inside a pair of single quotes which for example can be:

0 – zero placeholder, gives a digit if present – zero otherwise
# – digit placeholder, gives a digit if present, nothing otherwise
. – decimal point – determines where the decimal seperator should be
, – group separator – gives the localized group separator. Can also be used at the end to divide the number with 1000 for each comma
% – percentage placeholder – if at the end – multiplies number with 100 and gives percentage symbol at end

See more at:




2009-11-19 (Thursday)

T-SQL Converting DateTime to varchar – swedish date format

Filed under: Developing — Terje Isaksen @ 10:13

2009-11-12 (Thursday)

C# App.Config and static classes

Filed under: Developing — Terje Isaksen @ 17:40
Tags: , ,

To make the application configurable, so one can avoid to rewrite and recompile is to use App.Config.

    <add key = "MySetting" value="1223"/>

To access this – add an reference to System.Configuration and then in the code write

string x = System.Configuration.ConfigurationSettings.AppSettings.Get("MySetting")

Now, this is a little long to write, if it is to be used in many places. The solution is to encapsulate it in a static class.

A static class is a class that don´t needs to be instanciated. The values of the properties are set at start, and cannot be changed. Perfect for config-settings.

using System;
using System.Configuration;

namespace Something
 public static class AppResources
 public static string MySetting =  System.Configuration.ConfigurationSettings.AppSettings.Get( "MySetting" );

No need for set or get here.

And it is used like this:

string x = AppResources.MySetting;

And no () after the property name, of course.

2009-11-03 (Tuesday)

WPF Refresh window

Filed under: Developing — Terje Isaksen @ 17:18

Is done by


Create a free website or blog at WordPress.com.