.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> Silverlight >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Working with Image and Radio Button control in Silverlight 3.0

Posted By:Dhananjay Kumar       Posted Date: February 24, 2010    Points: 25    Category: Silverlight    URL: http://www.dotnetspark.com  

Working with Image and Radio Button control in Silverlight 3.0. In this article, I will explain about how to work with Radio Button control of Silverlight. I will also explain how to rotate image in silverlight.
 

Objective

In this article, I will explain couple of things step by step
  1. How to work with Radio Button control of Silverlight 3.0
  2. How to Rotate Image in Silverlight
Expected Output

1.gif


On selecting Radio Button Image will rotate in some angle.

2.gif

3.gif


Procedure

Create a Silverlight application by File -> New -> Project -> SilverLight then selecting Silverlight Application project template.

4.gif

Host the SilverLightApplication1 in Web Application

5.gif

Design the Silverlight page. Add Radio Buttons as shown below

MainPage.Xaml


  
  
  
  
  
  
  
  
  
  
  
  

Code Behind
  1. Add same event for click on all radio buttons.
  2. In the click event of radio buttons, I am assigning sender's name and checking it in a switch case.

    string
    radioButton = ((FrameworkElement)sender).Name;
    switch (radioButton)
    {
    }
  3. Rotation of image is being performed by RotateTransform class.

    RotateTransform rotate = new RotateTransform();
  4. In click event of Button we are checking radio button's isChecked property. If IsChecked is true for a radio button it means that radio button is selected.

    if
    (rdBtnLeft.IsChecked == true)
    {

    }
MainPage.Xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace SilverlightApplication1
{
  public partial class MainPage : UserControl
  {
  int parameter = 0;
  public MainPage()
  {
  InitializeComponent();
  }
  private void rdBtnName_Click(object sender, RoutedEventArgs e)
  {
  RotateTransform rotate = new RotateTransform();
  string radioButton = ((FrameworkElement)sender).Name;
  switch (radioButton)
  {
  case "rdBtnLeft":
  rotate.Angle = 30;
  imgToDisplay.RenderTransform = rotate; 
  break;
  case "rdBtnRight":
  rotate.Angle = 45;
  imgToDisplay.RenderTransform = rotate; 
  break; 
   case "rdBtnUp":
  rotate.Angle = 60;
  imgToDisplay.RenderTransform = rotate; 
  break; 
  case "rdBtndown" :
  rotate.Angle = 360;
  imgToDisplay.RenderTransform = rotate; 
  break; 
  }
  }
  private void btnRotate_Click(object sender, RoutedEventArgs e)
  {
  RotateTransform rotate = new RotateTransform();
  if (rdBtnLeft.IsChecked == true)
  {
  rotate.Angle = 30;
  imgToDisplay.RenderTransform = rotate; 
  }
  else if (rdBtnRight.IsChecked == true)
  {
  rotate.Angle = 45;
  imgToDisplay.RenderTransform = rotate; 
  }
  else if (rdBtnUp.IsChecked == true)
  {
  rotate.Angle = 60;
  imgToDisplay.RenderTransform = rotate; 
  }
  else
  {
  rotate.Angle = 90;
  imgToDisplay.RenderTransform = rotate; 
  }
  }
  }
}

Conclusion


In this article, I explained how to work with Radio Button control of Silverlight. I also explained how to rotate image in silverlight. Thanks for reading .

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend