SetValue Method

Sets the specified property or event to the specified value.

XAML
Cannot use methods in XAML.
Scripting
object.SetValue(propertyName, value)

Parameters

propertyName

string

The name of the dependency property to set.

value

object

The value to set the property to.

Remarks

You can use the SetValue method to set the value of any Silverlight property. However, you generally do not need this method to set property values, because all Silverlight properties support a more direct property syntax.

You can also use SetValue to set the value of Silverlight attached properties such as Canvas.Left. In this case, the attached property name is the owner class name for the attached property, a dot, and the attached property name: object.SetValue("ownerType.propertyName",value). Attached properties also support a more direct property syntax, in the form object["ownerType.propertyName"] = value.

Examples

The following JavaScript example shows how to set a property value by using both the SetValue method and typical property notation:

JavaScript
function onMouseEnter(sender, index)
{
    // Set the property value using the SetValue method.
    sender.setValue("opacity", 0.5);

    // Set the property value using the equivalent "." notation.
    sender.opacity = 0.5;
}

Applies To

Accessibility, ArcSegment, BeginStoryboard, BezierSegment, Boolean, Brush, Canvas, Color, ColorAnimation, ColorAnimationUsingKeyFrames, ColorKeyFrame, ColorKeyFrameCollection, DependencyObject, DiscreteColorKeyFrame, DiscreteDoubleKeyFrame, DiscretePointKeyFrame, DoubleAnimation, DoubleAnimationUsingKeyFrames, DoubleKeyFrame, DoubleKeyFrameCollection, Downloader, DrawingAttributes, Duration, Ellipse, EllipseGeometry, EventTrigger, Geometry, GeometryCollection, GeometryGroup, Glyphs, GradientStop, GradientStopCollection, Image, ImageBrush, InkPresenter, Inlines, KeySpline, KeyTime, Line, LinearColorKeyFrame, LinearDoubleKeyFrame, LinearGradientBrush, LinearPointKeyFrame, LineBreak, LineGeometry, LineSegment, Matrix, MatrixTransform, MediaAttribute, MediaAttributeCollection, MediaElement, Path, PathFigure, PathFigureCollection, PathGeometry, PathSegment, PathSegmentCollection, Point, PointAnimation, PointAnimationUsingKeyFrames, PointKeyFrame, PointKeyFrameCollection, PolyBezierSegment, Polygon, Polyline, PolyLineSegment, PolyQuadraticBezierSegment, QuadraticBezierSegment, RadialGradientBrush, Rect, Rectangle, RectangleGeometry, RepeatBehavior, ResourceDictionary, RotateTransform, Run, RuntimeErrorEventArgs, ScaleTransform, SkewTransform, SolidColorBrush, SplineColorKeyFrame, SplineDoubleKeyFrame, SplinePointKeyFrame, Storyboard, Stretch, Stroke, StrokeCollection, StylusInfo, StylusPoint, StylusPointCollection, TextBlock, Timeline, TimelineCollection, TimelineMarker, TimelineMarkerCollection, TimelineMarkerEventArgs, TimeSpan, TransformCollection, TransformGroup, TranslateTransform, TriggerActionCollection, TriggerCollection, VisualCollection, VideoBrush

See Also

Referencing and Modifying Objects
GetValue

Community Additions

Show: