C# Corner
Tech
News
Videos
Forums
Trainings
Books
Events
More
Interviews
Jobs
Live
Learn
Career
Members
Blogs
Challenges
Certifications
Bounties
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
How to scale images in Silverlight
WhatsApp
Praveen Kumar
16y
16.4
k
0
5
Resource
0
We can do the image scaling from XAML as well as from code-behind.
XAML:
<
UserControl
xmlns
=
http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns
:
x
=
http://schemas.microsoft.com/winfx/2006/xaml
x
:
Class
="imginSL.MainPage"
Width
="640"
Height
="480">
<
Grid
x
:
Name
="LayoutRoot"
Background
="White">
<
Image
x
:
Name
="img"
Margin
="151,127,208,142"
Source
="Waterfall.jpg"
Stretch
="Fill">
<
Image.RenderTransform
>
<
ScaleTransform
x
:
Name
="imagescale"
ScaleX
="1.2"
ScaleY
="1.2"
CenterX
="100"
CenterY
="100">
</
ScaleTransform
>
</
Image.RenderTransform
>
</
Image
>
</
Grid
>
</
UserControl
>
From Code-behind:
ScaleTransform
myscale =
new
ScaleTransform
();
myscale.ScaleX = myscale.ScaleX * 2;
myscale.ScaleY = myscale.ScaleY * 2;
myscale.CenterX = img.Width / 2;
myscale.CenterY = img.Height / 2;
img.RenderTransform = myscale;
silverlight
rendertransform
scaletransform