private int GetXValue(BitmapSource bitmapSource, string value) { switch (value.Trim().ToLower()) { case "left": return 0; case "right": return bitmapSource.PixelWidth; case "center": return bitmapSource.PixelWidth / 2; default: var val = int.Parse(value); val = Math.Max(0, val); val = Math.Min(bitmapSource.PixelWidth, val); return val; } }