How to Set Values in Silverlight
Knowing how to set values to Silverlight objects can save you time when developing Silverlight applications. Silverlight is a Microsoft product used to build rich interaction applications for the Windows Phone, web and desktop using the .NET Framework. The .NET Framework is a class library made of classes, interfaces and value types required in Silverlight applications. You can create a simple Silverlight application and accomplish the task of setting a value to an object.
Instructions
-
-
1
Start Microsoft Visual Web Developer Express, then select "New Project" from the left pane of the screen. Expand "Visual Basic" under "Installed Templates" and select "Silverlight." Double-click "Silverlight Application" to create a new project.
-
2
Leave the default settings in the "New Silverlight Application" dialog box. Click "OK." Double-click "Button" to add a new button to the project. Double-click "Ellipse" to add a new ellipse.
-
-
3
Double-click "Button" to open the "MaintPage.xaml.vb" module. Press "Ctrl" and "A," then press "Delete" to remove all existing code.
-
4
Copy and paste the following code to resize the ellipse using the "SetValue" property:
Partial Public Class MainPage
Inherits UserControl
Public Sub New()
InitializeComponent()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
Ellipse1.Width = 10
Ellipse1.Height = 10
Ellipse1.SetValue(Canvas.TopProperty, 200.0)
Ellipse1.SetValue(Canvas.LeftProperty, 200.0)
End Sub
End Class
-
5
Press "F5" to run the program, then click "Button" to resize the ellipse.
-
1
References
- Photo Credit internet image by Soja Andrzej from Fotolia.com