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
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
'****************************** Module Header ******************************'
' Module Name:	MainPage.xaml.vb
' Project:		VBSL3PixelShader
' Copyright (c) Microsoft Corporation.
' 
' This example demonstrates how to use new pixel shader feature in 
' Silverlight 3. It mainly covers two parts:
' 
' 1. How to use built-in Effect such as DropShadowEffect.
' 2. How to create a custom ShaderEffect and use it in the application.
' 
' This source is subject to the Microsoft Public License.
' See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
' All other rights reserved.
' 
' History:
' * 7/23/2009 01:00 PM Allen Chen Created
' * 7/29/2009 6:00 PM Jialiang Ge Reviewed
'***************************************************************************'

#Region "Imports directives"

Imports System.Windows.Threading
Imports System.Windows.Media.Effects

#End Region


Partial Public Class MainPage
    Inherits UserControl

    ' A timer used to reduce the value of _amplitude gradually.
    Private _timer As DispatcherTimer = New DispatcherTimer()

    ' Amplitude that is used to pass to PixelShaderConstantCallback
    Private _amplitude As Double

    ' Center (mouse position) that is used to pass to PixelShaderConstantCallback
    Private _center As Point


    Public Sub New()

        InitializeComponent()

        'Initialize timer and hook Tick event.
        _timer.Interval = TimeSpan.FromMilliseconds(50)
        AddHandler _timer.Tick, AddressOf _timer_Tick

    End Sub


    ''' <summary>
    ''' This event handler reduce the amplitude and apply a new 
    ''' CycleWateryEffect on each tick.
    ''' </summary>
    Private Sub _timer_Tick(ByVal sender As Object, ByVal e As EventArgs)

        If Me._amplitude > 0.0 Then
            Dim effect As CycleWateryEffect = New CycleWateryEffect( _
            New Uri("/VBSL3PixelShader;component/cyclewatery.ps", UriKind.Relative))
            effect.Center = Me._center
            effect.Amplitude = Me._amplitude
            Me.ImagePixelShader.Effect = effect
            Me._amplitude -= 0.05
        Else
            Me._timer.Stop()
        End If

    End Sub

    ''' <summary>
    ''' This event handler get the current mouse position, assign it to a 
    ''' private field and start the timer to apply new CycleWateryEffect.
    ''' </summary>
    Private Sub UserControl_MouseLeftButtonDown(ByVal sender As Object, _
                                                ByVal e As MouseButtonEventArgs)

        Me._center = New Point(e.GetPosition(Me.ImagePixelShader).X / _
                               Me.ImagePixelShader.ActualWidth, e.GetPosition( _
                               Me.ImagePixelShader).Y / Me.ImagePixelShader.ActualHeight)
        Me._amplitude = 0.5
        _timer.Start()

    End Sub
End Class


''' <summary>
''' CycleWateryEffect class is a custom ShaderEffect class.
''' </summary>
Public Class CycleWateryEffect
    Inherits ShaderEffect

    ''' <summary>
    ''' The following two DependencyProperties are the keys of this custom ShaderEffect.
    ''' They create a bridge between managed code and HLSL(High Level Shader Language).
    ''' The PixelShaderConstantCallback will be triggered when the propery get changed.
    ''' The parameter of the callback represents the register.
    ''' For instance, here the 1 in PixelShaderConstantCallback(1) represents C1 of the
    ''' following HLSL code. In another word, by changing
    ''' the Amplitude property we assign the changed value to the amplitude variable of the
    ''' following HLSL code:
    ''' <code>
    ''' sampler2D input : register(S0);
    ''' float2 center:register(C0);
    ''' float amplitude:register(C1);
    ''' float4 main(float2 uv : TEXCOORD) : COLOR
    ''' {
    ''' if(pow((uv.x-center.x),2)+pow((uv.y-center.y),2)<0.15)
    ''' {
    ''' uv.y = uv.y  + (sin(uv.y*100)*0.1*amplitude);
    ''' }
    ''' return tex2D( input , uv.xy);
    ''' }
    ''' </code>
    ''' </summary>

    Public Shared ReadOnly AmplitudeProperty As DependencyProperty = _
    DependencyProperty.Register("Amplitude", GetType(Double), GetType(CycleWateryEffect), _
                                New PropertyMetadata(0.1, ShaderEffect.PixelShaderConstantCallback(1)))

    Public Shared ReadOnly CenterProperty As DependencyProperty = _
    DependencyProperty.Register("Center", GetType(Point), GetType(CycleWateryEffect), _
                                New PropertyMetadata(New Point(0.5, 0.5), ShaderEffect.PixelShaderConstantCallback(0)))

 
    Public Sub New(ByVal uri As Uri)

        Dim u As Uri = uri
        Dim psCustom As PixelShader = New PixelShader()
        psCustom.UriSource = u
        PixelShader = psCustom

        MyBase.UpdateShaderValue(CenterProperty)
        MyBase.UpdateShaderValue(AmplitudeProperty)

    End Sub


    Public Property Amplitude() As Double
        Get
            Return CDbl(MyBase.GetValue(AmplitudeProperty))
        End Get
        Set(ByVal value As Double)
            MyBase.SetValue(AmplitudeProperty, value)
        End Set
    End Property


    Public Property Center() As Point
        Get
            Return CType(MyBase.GetValue(CenterProperty), Point)
        End Get
        Set(ByVal value As Point)
            MyBase.SetValue(CenterProperty, value)
        End Set
    End Property

End Class

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)

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 | Mobile
Web02 | 2.8.140721.1 | Last Updated 12 Dec 2009
Article Copyright 2009 by All-In-One Code Framework
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid