
|
Embedding CreateSilverlight
in HTML <div id="MySilverlightHost"> <script type="text/javascript"> CreateSilverlight(); </script> </div> |
|
CreateSilverlight.js (updated for RC) function createSilverlight() Silverlight.createObject( "xaml/MyInkCanvas.xaml", MySilverlightHost, "wpfobj", {width:'400', height:'200', inplaceInstallPrompt:false, background:'lightgray', isWindowless:'false', framerate:'36', version:'1.0'}, {onError:null, onLoad:null}, null); |
|
MyInkCanvas.xaml (updated for RC) <!--this does not include the addition of the pen image--> <Canvas xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Loaded="javascript:root_Loaded" x:Name="root" Width="800" Height="400"> <InkPresenter x:Name="inkPresenterElement" Background="transparent" Width="800" Height="400" MouseLeftButtonDown="InkPresenterMouseDown" MouseMove="InkPresenterMouseMove" MouseLeftButtonUp="InkPresenterMouseUp"/> </Canvas> |
|
ink.js (from
Gavin Gear at Microsoft) var wpf; var inkPresenter; // Corresponds to InkPresenter element in xaml var newStroke = null; // The Stroke variable we’ll use here in mouse handlers var currentColor=\"#FF000000\"; //black function root_Loaded(sender, args) { wpf = document.getElementById(\"wpfobj\"); inkPresenter = sender.findname(\"inkPresenterElement\"); } // Capture mouse and create the stroke function InkPresenterMouseDown(sender,args) { inkPresenter.CaptureMouse(); newStroke = wpf.content.createFromXaml(\'<Stroke/>\'); newStroke.StylusPoints.AddStylusPoints(args.GetStylusPoints(inkPresenter)); newStroke.DrawingAttributes.Color=currentColor; inkPresenter.Strokes.Add(newStroke); } // Add the new points to the Stroke we’re working with function InkPresenterMouseMove(sender,args) if (newStroke != null) { newStroke.StylusPoints.AddStylusPoints(args.GetStylusPoints(inkPresenter)); } } // Release the mouse function InkPresenterMouseUp(sender,args) { newStroke = null; } |
|
|