Friday, May 22, 2009

Making a 3d spin of an Image in Silverlight 3.0

Hi Friends,

I am with an another intresting feature in Silverlight 3.0. It's the 3 dimensional spin of any container in Silverlight 3

In this example, we are taking an example of an image to be moved in 3-d mode through 3 sliders.

Xaml Code :

<Grid x:Name="LayoutRoot" Background="Transparent">

<Grid x:Name="3dcontainer" Margin="250,160,233,150">
   <Grid.Projection>
       <PlaneProjection x:Name="Muthu"/>
   </Grid.Projection>

<Image x:Name="image" Source="Image1.jpg" Stretch="fill"/>

</Grid>

<StackPanel>

   <Slider x:Name="x" Height="20" Maximum="360" value="{Binding ElementName=Muthu, Path=RotationX, Mode=TwoWay}"/>
   <Slider x:Name="y" Height="20" Maximum="360" value="{Binding ElementName=Muthu, Path=RotationY, Mode=TwoWay}"/>
   <Slider x:Name="z" Height="20" Maximum="360" value="{Binding ElementName=Muthu, Path=RotationZ, Mode=TwoWay}"/>   

</StackPanel>

</Grid>


Output:

On sliding each slider the rotation will happen appropriately! Try out! Very cool feature , that can be utilized for 3-d stuffs.

As per my knowledge, there is a software named ZAM-3d which can create xaml for 3d objects created through it. So that can be placed into a grid in silverlight and using the same concept which I have explained above, we can achieve a 360 degree rotation of items on web.

Soon you can find an video in my personal site fmass.com related to this post!

This is amazing!

Cheers~!
Muthaiah
www.fmass.com

Element Binding in Silverlight 3

Hi Friends,

In silverlight 3,  we can have direct element binding. the below example will demonstrate the same in simple xaml codes.  So What ever you type in txt1 will automatically get binded to txt2. 

Xaml Code :

<TextBox  x:Name="txt1" Text="welcome"/>

<Textbox  x:Name="txt2" Text={Binding Text, ElementName=txt1}/>

Cheers!
Muthaiah
www.fmass.com

Simple Navigation link to a different website in silverlight 2.0

Hi Friends,

This following code explains how to make a simple navigation link , which opens in a seperate browser page in silverlight 2.0

Xaml Code:

<TextBlock HorizontalAlignment="Right" Margin="0,32,0,22" Width="118" Text="Fmass - creativity powered" TextWrapping="Wrap" Foreground="#FF808080" TextDecorations="Underline" x:Name="fmasstxt" MouseLeftButtonDown="fmass_MouseLeftButtonDown" Cursor="Hand"/>

C# code:

using System.Windows.Browser;

private void fmass_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            HtmlPage.Window.Navigate(new Uri("http://www.fmass.com") , self);

        }



Cheers! 
Muthaiah
www.fmass.com

Thursday, May 21, 2009

Continous background music player in silverlight 2.0

Hi Friends,

This is a small example of how to incorporate background music for a website in silverlight 2.0, which will have continous stream of music, where you shuld make sure the editing of music is in such a  way that, you can feel as if it is continous.

Xaml code :

<MediaElement Height="34" Source="assets/bgmusic.mp3" MediaEnded="bgaudioplayer_MediaEnded"   Position="0" HorizontalAlignment="Right" Margin="0,0,44,227" VerticalAlignment="Bottom" Width="32" x:Name="bgaudioplayer"/>

C# backend code :

private void bgaudioplayer_MediaEnded(object sender, RoutedEventArgs e)
        {
            bgaudioplayer.Position = System.TimeSpan.FromSeconds(0);
            bgaudioplayer.Play();
        }


Cheers!
Muthaiah
www.fmass.com