private int GetYValue(BitmapSource bitmapSource, string value) { switch (value.ToLower()) { case "top": return 0; case "bottom": return bitmapSource.PixelHeight; case "center": return bitmapSource.PixelHeight / 2; default: var val = int.Parse(value); val = Math.Max(0, val); val = Math.Min(bitmapSource.PixelHeight, val); return val; } }