Reputation: 13434
Test.aspx page:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="XMLPraktijkOpdrachtJavascript.Test" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Test</title>
<script type="text/javascript" src="Javascript/Test.js"></script>
</head>
<body>
<object id="TestPage" width="100%" height="100%" type="application/x-silverlight-2">
<param name="source" value="Xaml/Test.xaml"/>
</object>
</body>
</html>
Test.xaml page:
<?xml version="1.0" encoding="UTF-8"?>
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Loaded="onLoaded">
<Button Width="50" Height="50" Name="Test">TEST</Button>
</Grid>
Test.js file:
// Event function when page gets loaded
function onLoaded() {
alert('In TestPage');
}
Without the button, it works fine. With the button, it fails. Why can't I use a button in Silverlight? The System.Windows.Controls is added to the project.
Upvotes: 0
Views: 546
Reputation: 65044
Having read a very similar question you've asked before, I'm not sure you understand the fundamental difference between Silverlight 1 and Silverlight 2 or later.
Your <object>
element has the attribute type="application/silverlight-2"
, which specifies Silverlight 2 or later. However, the source
parameter specifies a .xaml
file, which (I believe) is how Silverlight 1 works.
Silverlight 2 and later require the Silverlight code to be developed in a separate project. These Silverlight projects compile all the Silverlight code into a .xap
file. You then add the Silverlight application to your web project, which arranges for the compiled .xap
file to be copied into a ClientBin
folder within your web project. You can then have your web project serve the .xap
file to your browser. With Silverlight 1, it appears that the .xaml
files are served up from within your web project.
Is your project a Silverlight 1 project or not? If it's an existing application, is there any chance of migrating it to a later version? If you've been lumbered with maintaining a large legacy Silverlight 1 application, all I can say is I'm really sorry for you.
There is no good reason at all to write new Silverlight 1 applications any more. It's fundamentally different to other versions of Silverlight and it has so many limitations. In particular, there is no Button
in Silverlight 1, as someone has already pointed out to you in a comment to your previous question. This is likely to be the cause of the error you are seeing.
Upvotes: 3
Reputation: 3854
you can't just use a "xaml file" like that. You need a "silverlight project" that outputs a xap file which you can embed in your web page.
Try creating a silverlight application, this will create the silverilght project, prompt and create a web application for you, configure the web app to display the silverlight project and gets you up and running more quickly ;)
Hope this helps
Upvotes: 2