다음을 통해 공유


PressureFactor

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets the pressure factor of the stylus on the screen.

<object PressureFactor="Double"  .../>
value = object.PressureFactor
object.PressureFactor = value

Property Value

Type: Double

The pressure factor of the stylus on the screen.

This property is read/write. The default value is 0.5.

Managed Equivalent

PressureFactor

Remarks

The allowed range is 0 to 1.0. Values obtained from input will always be within this range. Setting the value outside this range raises an error.

The value is a factor of the total possible pressure.

The typical scenario for this property is to modify the DrawingAttributes on the basis of the PressureFactor that is captured in a StylusPoint obtained from user input. However, note that while PressureFactor comes from individual points, DrawingAttributes must apply to an entire Stroke.

Example

The following example uses the PressureFactor property to determine the size of a stroke. The PressureFactor is obtained from the first StylusPoint of each stroke. The stroke Width and Height are then calculated by multiplying the PressureFactor by 20.

var agCtrl;
var inkPresenter; // Corresponds to InkPresenter element in XAML.
var newStroke = null; // The Stroke variable we'll use here in mouse handlers.
var daWidth;
var daHeight;

function root_Loaded(sender, args) 
{
    // Get the HTML object that contains the Silverlight plug-in.
    agCtrl = sender.GetHost();
    inkPresenter = sender.findname("inkPresenterElement");
}

// Capture mouse movement when the left button is pressed, and then create the stroke.
function InkPresenterMouseDown(sender,args)
{
   inkPresenter.CaptureMouse();
   newStroke = agCtrl.content.createFromXaml('<Stroke/>');
   
   // Get the device type.
   if(args.GetStylusInfo().deviceType == "Stylus")
   {
     var sps = args.GetStylusPoints(inkPresenter);
     SetStylusStrokeSize(sps);
   }
   // If the device type is not a stylus, use the default stroke height and width.
   else
   {
     daWidth = 3;
     daHeight = 3;
   }
   
   // Set the drawing attribute properties.
   newStroke.DrawingAttributes.Width = daWidth;
   newStroke.DrawingAttributes.Height = daHeight;
   newStroke.DrawingAttributes.Color = "Blue";
   newStroke.DrawingAttributes.OutlineColor = "Orange";
   
   newStroke.StylusPoints.AddStylusPoints(args.GetStylusPoints(inkPresenter));
   inkPresenter.Strokes.Add(newStroke);
}

// Add the new points to the Stroke we're working with.
function InkPresenterMouseMove(sender,args)
{
   if (newStroke != null)
   {
      newStroke.StylusPoints.AddStylusPoints(args.GetStylusPoints(inkPresenter));
   }
}

// Release the mouse.
function InkPresenterMouseUp(sender,args)
{
   newStroke = null;
}

// Set the size of the stroke based on the initial pressure factor of the stroke.
function SetStylusStrokeSize(sps)
{
    var p;
    // Set variable p to the first StylusPoint in the Stroke.
    p = sps.getItem(0).pressureFactor;
    daWidth = p * 20.0;
    daHeight = p * 20.0;
}

Applies To

StylusPoint