void CreateWidgets() { grid.Children.Clear(); var effect = CurrentEffect; if (effect == null) { return; } var metadata = EffectMetadata.Get(effect.Type); // Create XAML elements and choose their label strings. var widgets = new List <UIElement>(); var widgetNames = new List <string>(); foreach (var parameter in metadata.Parameters) { CreateParameterWidgets(effect, parameter, widgets, widgetNames); if (widgetNames.Count < widgets.Count) { widgetNames.Add(FormatParameterName(parameter.Name)); } } // Populate the grid. for (int row = 0; row < widgets.Count; row++) { var label = new TextBlock { Text = widgetNames[row] }; AddToGrid(label, row, 0); AddToGrid(widgets[row], row, 2); } }
public ICanvasImage Apply(ICanvasImage image, ref Rect?bounds) { if (!IsEnabled) { return(image); } var metadata = EffectMetadata.Get(type); // Instantiate the effect. var effect = (ICanvasImage)Activator.CreateInstance(metadata.ImplementationType); // Set the effect input. SetProperty(effect, "Source", image); // Set configurable parameter values. foreach (var parameter in metadata.Parameters) { var value = GetParameter(parameter); SetProperty(effect, parameter.Name, value); // Track the image bounds if cropping changes them. if (this.Type == EffectType.Crop && parameter.Name == "SourceRectangle") { bounds = bounds.HasValue ? RectHelper.Intersect(bounds.Value, (Rect)value) : (Rect)value; } } // Set any constant values. foreach (var constant in metadata.Constants) { SetProperty(effect, constant.Key, constant.Value); } return(effect); }