The next thing I thought about was how my page would use the javascript to interact with the page and the XAML. So, in my page I have a simple input control that the onclick method is set to call a javascript method called "OnLookup()" From here this kicks off my call to the web service. Lets take a look at the javascript file:
var _results;
function OnLookup()
{
ClearList();
MyComplexType.MyInformation.MyComplexTypeService.GetMyInformation(OnSucceeded);
}
function OnSucceeded(result)
{
_results = result;
Array.forEach(result,AddXamlElement);
}
function ClearList()
{
//This gets a reference to the aghost control on the HTML page that holds the XAML object.
var canvas = $get("WpfeControl");
//next I get the canvas I want to add the data to in the form of a XAML rectangle.
var properCanvas = canvas.findName("DataCanvas");
//clear all the elements
properCanvas.children.clear();
}
function AddXamlElement(element,index)
{
//index automatically increments for each call, so I use that to name my rectangles
//This gets a reference to the aghost control on the page that holds the XAML object.
var canvas = $get("WpfeControl");
//next I get the canvas I want to add the data to in the form of a XAML rectangle.
var properCanvas = canvas.findName("DataCanvas");
//Create a new XAML rectangle and give it a namespace and a name
var xamlRect = '<Rectangle xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="';
xamlRect += "Rect_"+index;
xamlRect += '" Height="30" Width="170" Canvas.Left="2" Canvas.Top="';
if(index === 0){xamlRect += '2';}
else{xamlRect += (32 * index);}
xamlRect += '" Stroke="White" StrokeThickness="1" MouseLeftButtonDown="javascript:DoSomething">';
xamlRect += '<Rectangle.Fill>';
xamlRect += '<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">';
xamlRect += '<GradientStop Color="Black" Offset="0.0" />';
xamlRect += '<GradientStop Color="Blue" Offset="0.50" />';
xamlRect += '<GradientStop Color="Black" Offset="1.0" />';
xamlRect += '</LinearGradientBrush>';
xamlRect += '</Rectangle.Fill>';
xamlRect += '</Rectangle>';
var xamlText = '<TextBlock xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="';
xamlText += "TextBlock_"+index;
xamlText += '" Text="';
xamlText += element.Day;
xamlText += '/' + element.Month;
xamlText += '/' + element.Year;
xamlText += '" FontSize="10" Foreground="White" Canvas.Left="8" Canvas.Top="';
xamlText += (32 * index)+4;
xamlText += '" MouseLeftButtonDown="javascript:DoSomething"/>';
//add my rectangle with an event
var newControl = canvas.CreateFromXaml(xamlRect);
//add my text with an event
var newControl2 = canvas.CreateFromXaml(xamlText);
properCanvas.children.Add(newControl);
properCanvas.children.Add(newControl2);
}
function DoSomething(sender,args)
{
//parse the element in the array stored globally and use that to find the element in the array
}