Ejemplo n.º 1
0
        // Applies the selected options to the image brush.
        private void UpdateBrush(object sender, RoutedEventArgs args)
        {
            try
            {
                myImageBrush.ImageSource = (_selectedButton.Content as Image).Source;
                myImageBrush.Stretch     = (Stretch)Enum.Parse(typeof(Stretch), (string)stretchSelector.SelectedItem);
                myImageBrush.AlignmentX  =
                    (AlignmentX)Enum.Parse(typeof(AlignmentX), (string)horizontalAlignmentSelector.SelectedItem);
                myImageBrush.AlignmentY =
                    (AlignmentY)Enum.Parse(typeof(AlignmentY), (string)verticalAlignmentSelector.SelectedItem);
                myImageBrush.TileMode      = (TileMode)Enum.Parse(typeof(TileMode), (string)tileSelector.SelectedItem);
                myImageBrush.ViewportUnits =
                    (BrushMappingMode)
                    Enum.Parse(typeof(BrushMappingMode), (string)viewportUnitsSelector.SelectedItem);
                myImageBrush.ViewboxUnits =
                    (BrushMappingMode)Enum.Parse(typeof(BrushMappingMode), (string)viewboxUnitsSelector.SelectedItem);

                var myRectConverter = new RectConverter();
                var parseString     = viewportEntry.Text;

                if (!string.IsNullOrEmpty(parseString))
                {
                    myImageBrush.Viewport = (Rect)myRectConverter.ConvertFromString(parseString);
                }
                else
                {
                    myImageBrush.Viewport = Rect.Empty;
                    viewportEntry.Text    = "Empty";
                }

                parseString = viewboxEntry.Text;

                if (!string.IsNullOrEmpty(parseString) && parseString.ToLower() != "(auto)")
                {
                    myImageBrush.Viewbox = (Rect)myRectConverter.ConvertFromString(parseString);
                }
                else
                {
                    viewboxEntry.Text    = "Empty";
                    myImageBrush.Viewbox = Rect.Empty;
                }
            }
            catch (InvalidOperationException invalidOpEx)
            {
                MessageBox.Show("Invalid Viewport or Viewbox. " + invalidOpEx);
            }
            catch (FormatException formatEx)
            {
                MessageBox.Show("Invalid Viewport or Viewbox. " + formatEx);
            }
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            RectConverter rc = new RectConverter();

            if (value == null)
            {
                return(new Rect(0, 0, 0, 0));
            }

            return(rc.ConvertFromString((String)value));
        }