Mega Code Archive

 
Categories / Silverlight / UI Controls
 

Zoom a TextBlock

<UserControl x:Class='SilverlightApplication3.MainPage'     xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'      xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'     xmlns:d='http://schemas.microsoft.com/expression/blend/2008'      xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006'      mc:Ignorable='d'      d:DesignWidth='640'      d:DesignHeight='480'>   <Grid x:Name="LayoutRoot" Background="White">     <TextBlock       HorizontalAlignment="Center"       VerticalAlignment="Center"       FontFamily="Verdana"       FontSize="20"       Foreground="DarkBlue"       Text="Use the wheel now!">       <TextBlock.RenderTransform>         <ScaleTransform x:Name="MyZoom"/>       </TextBlock.RenderTransform>     </TextBlock>   </Grid> </UserControl> //File: Page.xaml.cs using System; using System.Windows.Browser; using System.Windows.Controls; namespace SilverlightApplication3 {     public partial class MainPage : UserControl     {     public MainPage()     {       InitializeComponent();       HtmlPage.Document.AttachEvent("onmousewheel", ChangeZoomLevel);     }     private void ChangeZoomLevel(Object sender, HtmlEventArgs args)     {       ScriptObject EventData = args.EventObject;       if (EventData.GetProperty("wheelDelta") != null)       {         double Offset = Convert.ToDouble(EventData.GetProperty("wheelDelta"));         MyZoom.ScaleX += (Offset > 0 ? 0.1 : -0.1);         MyZoom.ScaleY += (Offset > 0 ? 0.1 : -0.1);       }     }   } }