Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

An Introduction to the Silverlight samples in the All-In-One Framework

, 12 Dec 2009 Ms-PL
This article introduces several Silverlight samples in the All-In-One Framework.
SilverlightIntroduction_src.zip
CSSL3LocalMessage
Properties
CSSL3MediaElement
CSSL3MediaElement
Properties
CSSL3MediaElement.Web
App_Data
ClientBin
CSSL3MediaElement.xap
Properties
ReadMe.mht
CSSL3PixelShader
cyclewatery.ps
Humpback Whale.jpg
Properties
CSSL3WriteableBitmap
Heart Empty.png
Properties
VBSL3Animation
My Project
VBSL3DeepZoom
VBSL3DeepZoom
images
home_hover.png
home_pressed.png
home_rest.png
My Project
Service References
DeepZoomServiceReference
configuration.svcinfo
configuration91.svcinfo
GenerateDeepZoomService.disco
GenerateDeepZoomService.wsdl
Reference.svcmap
ServiceReferences.ClientConfig
VBSL3DeepZoom.Web
App_Code
App_Data
Bin
DeepZoomTools.DLL
DeepZoomTools.DLL.refresh
ClientBin
GeneratedImages
GenerateDeepZoomService.svc
SourceImages
atom.png
background.jpg
cell.png
dna.png
Molecular.png
neutron.png
seed.png
wrap in bamboo.png
VBSL3HTMLBridge
VBSL3HTMLBridge
My Project
VBSL3HTMLBridge.Web
App_Data
ClientBin
VBSL3HTMLBridge.xap
My Project
Application.myapp
MyExtensions
Settings.settings
VBSL3Input
My Project
VBSL3LocalMessage
My Project
VBSL3MediaElement
ReadMe.mht
VBSL3MediaElement
My Project
VBSL3MediaElement.Web
App_Data
ClientBin
VBSL3MediaElement.xap
My Project
Application.myapp
MyExtensions
Settings.settings
VBSL3PixelShader
cyclewatery.ps
Humpback Whale.jpg
My Project
CSSL3Animation
Properties
CSSL3DeepZoom
CSSL3DeepZoom
images
home_hover.png
home_pressed.png
home_rest.png
Properties
Service References
DeepZoomServiceReference
configuration.svcinfo
configuration91.svcinfo
GenerateDeepZoomService.disco
GenerateDeepZoomService.wsdl
GenerateDeepZoomService1.wsdl
Reference.svcmap
ServiceReferences.ClientConfig
CSSL3DeepZoom.Web
App_Code
Bin
DeepZoomTools.DLL
DeepZoomTools.DLL.refresh
ClientBin
GeneratedImages
GenerateDeepZoomService.svc
SourceImages
atom.png
background.jpg
cell.png
dna.png
Molecular.png
neutron.png
seed.png
wrap in bamboo.png
ReadMe.mht
CSSL3HTMLBridge
CSSL3HTMLBridge
Properties
CSSL3HTMLBridge.Web
App_Data
ClientBin
CSSL3HTMLBridge.xap
Properties
CSSL3Input
Properties
========================================================================
    SILVERLIGHT APPLICATION : CSSL3Input Project Overview
========================================================================

/////////////////////////////////////////////////////////////////////////////
Use:

This example demonstrates how to handle mouse and keyboard event in 
Silverlight 3. It demonstrate following functionalities:

	Handle mouse/keyboard event
	Implement mouse drag function


/////////////////////////////////////////////////////////////////////////////
Prerequisites:

Silverlight 3 Tools for Visual Studio 2008 SP1
http://www.microsoft.com/downloads/details.aspx?familyid=9442b0f2-7465-417a-88f3-5e7b5409e9dd&displaylang=en

Silverilght 3 runtime:
http://silverlight.net/getstarted/


/////////////////////////////////////////////////////////////////////////////
Code Logic:

1.To Handle mouse/keyboard event. The normal way is creating an event handler 
and register handler on target control.

	<Canvas Margin="20" Background="AliceBlue" MouseEnter="Canvas_MouseEnter">

	private void Canvas_MouseEnter(object sender, MouseEventArgs e)
	{
		//handle event
	}

Another way to handle control event, is using AddHandler method. The API 
AddHandler provides a technique whereby you can attach a handler that will 
always be invoked for the route, even if some other handler earlier in the 
route has set Handled to true. For example, handling Button's 
MouseLeftButtonDown / MouseLeftButtonUp event

	((Button)sender).AddHandler(Button.MouseLeftButtonUpEvent,
		new MouseButtonEventHandler(Button_MouseLeftButtonUp),true);

	private void Button_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
	{
		//handle event
	}

2.To implement mouse drag function, we need combine the usage of 
MouseLeftButtonDown, MouseLeftButtonUp and MouseMove event.

	void Button_MouseMove(object sender, MouseEventArgs e)
	{
		if (isMouseCaptured)
		{
			var item= ((Button)sender);
			// Calculate the current position of the object.
			double deltaV = e.GetPosition(null).Y - mouseVerticalPosition;
			double deltaH = e.GetPosition(null).X - mouseHorizontalPosition;
			double newTop = deltaV + (double)item.GetValue(Canvas.TopProperty);
			double newLeft = deltaH + (double)item.GetValue(Canvas.LeftProperty);

			// Set new position of object.
			item.SetValue(Canvas.TopProperty, newTop);
			item.SetValue(Canvas.LeftProperty, newLeft);

			// Update position global variables.
			mouseVerticalPosition = e.GetPosition(null).Y;
			mouseHorizontalPosition = e.GetPosition(null).X;
		}
	}

	private void Button_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
	{
		isMouseCaptured = true;
		mouseVerticalPosition = e.GetPosition(null).Y;
		mouseHorizontalPosition = e.GetPosition(null).X;
		((Button)sender).CaptureMouse();
	}

	private void Button_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
	{
		isMouseCaptured = false;
		((Button)sender).ReleaseMouseCapture();
	}
        
3.To put UserControl in another UserControl, first we need register the 
usercontrol's namespace, then use usercontrol with this name 
"prefix_name:usercontrol_name"

	<cssinput:KeyboardSupport  xmlns:cssinput="clr-namespace:CSSL3Input" />
        
4.To bind list to listbox, first set ListBox.ItemsSource to list, then set 
databinding on ListBox.ItemTemplate. For details, please check
http://msdn.microsoft.com/en-us/library/cc265158(VS.95).aspx
and also please wait for the future releases of CodeFx.


/////////////////////////////////////////////////////////////////////////////
References:

Mouse Support
http://msdn.microsoft.com/en-us/library/cc189029(VS.95).aspx

Keyboard Support
http://msdn.microsoft.com/en-us/library/cc189015(VS.95).aspx

How to: Drag and Drop Objects in UI Layout
http://msdn.microsoft.com/en-us/library/cc189066(VS.95).aspx


/////////////////////////////////////////////////////////////////////////////

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

Share

About the Author

Microsoft All-In-One Code Framework delineates the framework and skeleton of Microsoft development techniques through typical sample codes in three popular programming languages (Visual C#, VB.NET, Visual C++). Each sample is elaborately selected, composed, and documented to demonstrate one frequently-asked, tested or used coding scenario based on our support experience in MSDN newsgroups and forums. If you are a software developer, you can fill the skeleton with blood, muscle and soul. If you are a software tester or a support engineer like us, you may extend the sample codes a little to fit your specific test scenario or refer your customer to this project if the customer's question coincides with what we collected.
http://cfx.codeplex.com/

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 12 Dec 2009
Article Copyright 2009 by All-In-One Code Framework
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid