1

I am having difficulties to understand why I can change the brush color but can't change the brush radius in a SurfaceInkCanvas. Here is what I do:

Double newSize = Math.Round(BrushRadiusSlider.Value,0);

drawingAttributes = new System.Windows.Ink.DrawingAttributes();

// Works :
drawingAttributes.Color = Colors.Yellow;
// Does not work :
drawingAttributes.Width = newSize;
drawingAttributes.Height = newSize;

canvas.DefaultDrawingAttributes = drawingAttributes;

For information, BrushRadiusSlider is a slider in the XAML and gives values between 1 and 100.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
  • 1
    What are you doing with the drawingAttributes? And what is the value of newSize? Please could you provide some XAML and a bit more code to indicate what you are doing with it? – Stephen Holt Nov 13 '12 at 10:48

2 Answers2

2

See here:
SurfaceInkCanvas.DefaultDrawingAttributes Property

You probably forgot to set the UsesTouchShape to false

afuzzyllama
  • 6,538
  • 5
  • 47
  • 64
Tawy
  • 36
  • 1
0

The issue is I think that the brush is not updating when the slider's value is changed. Your code above takes the value of the slider at one moment in time, and sets the width and height to that, but it is not linked to the slider.

To get it to update when the slider changes you would need to handle the SliderValueChanged event and reset the drawingAttributes then.

XAML:

<Slider x:Name="BrushRadiusSlider" Minimum="1" Maximum="100" Value="1" ValueChanged="SliderValueChanged"/>

Code:

private void SliderValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
    if (canvas != null)
    {
        var drawingAttributes = canvas.DefaultDrawingAttributes;
        Double newSize = Math.Round(BrushRadiusSlider.Value, 0);
        drawingAttributes.Width = newSize;
        drawingAttributes.Height = newSize;
    }
}
Stephen Holt
  • 2,360
  • 4
  • 26
  • 34