Question

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.

Was it helpful?

Solution

See here:
SurfaceInkCanvas.DefaultDrawingAttributes Property

You probably forgot to set the UsesTouchShape to false

OTHER TIPS

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;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top