Reputation:
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.
Upvotes: 1
Views: 1586
Reputation: 36
See here:
SurfaceInkCanvas.DefaultDrawingAttributes Property
You probably forgot to set the UsesTouchShape
to false
Upvotes: 2
Reputation: 2368
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;
}
}
Upvotes: 0