Subscribe - What everyone wants (besides more Wally).
Download.
View in Flash.
Show Notes:
- Silverlight .NET 1.1 Alpha.
- Debugging.
- Running in VS.NET Orcas Beta1
- Managed JavaScript.
Page.xaml source:
<Canvas x:Name="root"
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="SampleApplication.EventHandlingCanvas;assembly=ClientBin/SilverlightProject2.dll"
Loaded="Page_Loaded"
>
<Canvas Width="100" Height="30" Background="Gray" x:Name="Button1">
<TextBlock>Click me</TextBlock>
</Canvas>
<Canvas x:Name="Button2" Canvas.Top="50" Width="100" Height="30" Background="Gray">
<TextBlock>Click me too</TextBlock>
</Canvas>
</Canvas>
Page.xaml.cs source:
//------------------------------------------------------------------------------
// <copyright file="default.xaml.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace SampleApplication
{
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Controls;
using System.Windows.Shapes;
public partial class EventHandlingCanvas : Canvas
{
public void Page_Loaded(object o, EventArgs e)
{
// Required to initialize variables
InitializeComponent();
}
public EventHandlingCanvas()
{
this.Loaded += new EventHandler(EventHandlingCanvas_Loaded);
}
void EventHandlingCanvas_Loaded(object sender, EventArgs e)
{
Button2.MouseLeftButtonUp += new MouseEventHandler(OnClick);
Button1.MouseLeftButtonUp += new MouseEventHandler(OnClick);
Button1.MouseEnter += new MouseEventHandler(Button2_MouseEnter);
Button1.MouseLeave += new EventHandler(Button2_MouseLeave);
Button2.MouseEnter += new MouseEventHandler(Button2_MouseEnter);
Button2.MouseLeave += new EventHandler(Button2_MouseLeave);
}
void Button2_MouseLeave(object sender, EventArgs e)
{
Canvas cc = sender as Canvas;
SolidColorBrush sb = new SolidColorBrush();
sb.Color = Colors.Red;
cc.Background = sb;
TextBlock tb = cc.Children[0] as TextBlock;
tb.Text = "Mouse Left";
Button2.Cursor = Cursors.Default;
}
void OnClick(object sender, MouseEventArgs e)
{
Canvas cc = sender as Canvas;
SolidColorBrush sb = new SolidColorBrush();
sb.Color = Colors.Red;
cc.Background = sb;
TextBlock tb = cc.Children[0] as TextBlock;
if (tb.Text != "Clicked...")
tb.Text = "Clicked...";
else
tb.Text = "Click Me.";
}
void Button2_MouseEnter(object sender, MouseEventArgs e)
{
Canvas cc = sender as Canvas;
SolidColorBrush sb = new SolidColorBrush();
sb.Color = Colors.Red;
cc.Background = sb;
TextBlock tb = cc.Children[0] as TextBlock;
tb.Text = "Mouse Entered";
Button2.Cursor = Cursors.Hand;
}
}
}
Managed JavaScript / JScript source code examples
Default.aspx source code:
<%@ Page Language="ManagedJScript" CodeFile="Default.aspx.jsx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>JScript Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click"/><br />
<asp:Label ID="Label1" runat="server"
Text=""></asp:Label>
</div>
</form>
</body>
</html>
Default.aspx.jsx source code:
Import("System.Data");
Import("System.Data.SqlClient");
function Page_Load(sender, e){
}
function Button1_Click(sender, e)
{
Label1.Text = "Clicked.";
}