Like this
void RegisterControl(Binding binding, object val)
{
UIElement ctl = null;
var type = val.GetType();
if (type == typeof(double))
{
ctl = new DoubleUpDown();
BindingOperations.SetBinding(ctl, DoubleUpDown.ValueProperty, binding);
}
else if (type == typeof(int))
{
ctl = new IntegerUpDown();
BindingOperations.SetBinding(ctl, IntegerUpDown.ValueProperty, binding);
}
else if (type == typeof(long))
{
ctl = new LongUpDown();
BindingOperations.SetBinding(ctl, LongUpDown.ValueProperty, binding);
}
else if (type == typeof(byte))
{
ctl = new ByteUpDown();
BindingOperations.SetBinding(ctl, ByteUpDown.ValueProperty, binding);
}
else if (type == typeof(short))
{
ctl = new ShortUpDown();
BindingOperations.SetBinding(ctl, ShortUpDown.ValueProperty, binding);
}
if (ctl != null)
_grid.Children.Add(ctl);
}
It's ugly but it works...