Moving a TextBlock five pixels with GetValue and SetValue in Silverlight

<Canvas x:Name="parentCanvas"
Width="400" Height="400" Background="LightGray">
<TextBlock x:Name="myTextBlock"
Text="Click Me"
Cursor="Hand"
MouseLeftButtonUp="MyTextBlock_Click"
FontFamily="Verdana" />
</Canvas>
private void MyTextBlock_Click(object sender, MouseButtonEventArgs e)
{
double top =
(double)(myTextBlock.GetValue(Canvas.TopProperty));
double left =
(double)(myTextBlock.GetValue(Canvas.LeftProperty));
myTextBlock.SetValue(Canvas.TopProperty, (top+5));
myTextBlock.SetValue(Canvas.LeftProperty, (left+5));
}

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.