Resize Image thru Slider in Silverlight

Add Comment | May 18, 2010

Hello Guys,

I've been playing with slider on silverlight. Now the result is this, a simple resizing image thru slider. 

The Image below is the default size of my sample.

And the second Image below are the result when the slider slide to right and top.

The xaml layout are very simple:

<Slider Minimum="80" Maximum="238" Height="23" HorizontalAlignment="Center" Name="sldBottom" Width="246" Margin="27,226,27,1" />
<Slider Height="212" Minimum="80" Maximum="209" Name="sldRight" Width="28" Orientation="Vertical" Margin="271,9,1,29" />
<Image HorizontalAlignment="Center" Name="image1" Stretch="Fill" VerticalAlignment="Center" Source="/GBLOgs2;component/Images/logosai.JPG" Height="{Binding ElementName=sldRight,Path=Value}" Width="{Binding ElementName=sldBottom,Path=Value}" />

The Image1 Height are depending to the maximum value of sldRight and its value same with the situation of Image1 Width. The Image1 Height/Width = {Binding ElementName="NAME OF THE SLIDER", Path="THE VALUE OF SLIDER"}. When you slide the slider the image will resize.

And thats all. Happy Programming.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Basic Mouse Features in Silverlight

One Comment | May 16, 2010

Hi Guys,

I have basic sample on how to use some features of mouse events in Silverlight.

The picture.

The Mouse Activity Log is to record the all activity done on the projects. My simple snippets on how to add on the textbox is:

        protected void MessageLog(string msg)
        {
            txtMouseLog.Text += msg;
        }
 

For the Mouse Wheel sample this is the snippets:

        private void chkMouseWheel_Checked(object sender, RoutedEventArgs e)
        {
            image1.MouseWheel += new MouseWheelEventHandler(image1_MouseWheel);
        }
 
        void image1_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            ImgScale.ScaleX = e.Delta > 0 ? ImgScale.ScaleX * 1.5 : ImgScale.ScaleX * 0.8;
            ImgScale.ScaleY = e.Delta > 0 ? ImgScale.ScaleY * 1.5 : ImgScale.ScaleY * 0.8;
 
            e.Handled = true;
        }
 
 And the XAML:
       <Image Height="139" Name="image1" Stretch="Fill" Width="178" Source="/GBLOgs1;component/Images/Sunset.jpg">
           <Image.RenderTransform>
                <ScaleTransform x:Name="ImgScale"></ScaleTransform>
           </Image.RenderTransform>
       </Image
 
 
I have also the showing of mouse position:
 
        private void Mouse_MouseMove(object sender, MouseEventArgs e)
        {
            Point point = e.GetPosition(this);
            lblMouseLocation.Content = "X: " + point.X + "and Y: " + point.Y;
        }
 
        private void checkBox1_Checked(object sender, RoutedEventArgs e)
        {
            lblMouseLocation.Visibility = Visibility.Visible;
            MessageLog("Mouse Location Visible\n");
        }
 
        private void checkBox1_Unchecked(object sender, RoutedEventArgs e)
        {
            lblMouseLocation.Visibility = Visibility.Collapsed;
            MessageLog("Mouse Location Collapsed\n");
       
 
 And even the counting of clicked event:
 
        int clicked = 0;
        private void LayoutRoot_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Point point = e.GetPosition(this);
            clicked++;
 
            string msg = "Mouse Clicked " + clicked.ToString() + " time(s) " +
                                    "Mouse Location X and Y: " + point.X + " " + point.Y + "\n";
 
            MessageLog(msg);
        }
 

 

And now the result of above snippets. Happy Programming.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

VISUAL STUDIO 2010 GLOBAL LAUNCH

Add Comment | Apr 12, 2010

Hello Guys,

The Visual Studio 2010 is here.

You can test by downloading the free trial at this link http://www.microsoft.com/visualstudio/en-us/download and view the products features in this link http://www.microsoft.com/visualstudio/en-us/products .

You can even watch the live launch at http://www.microsoft.com/visualstudio/en-us/watch-it-live


Happy Programming.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Autocomplete in Silverlight with Visual Studio 2010

One Comment | Mar 05, 2010

Last week I keep searching on how to use the autocomplete in silverligth with visual studio 2010 but most of the examples that I find they are using a textbox or combobox for the autocomplete. I tried to study those examples and apply to the single autocomplete from tools on my silverlight project. And now this is the result. I will use a database again from my previous post (Silverlight Simple DataBinding in DataGrid) to show how the autocomplete works with database.


This is the output:

First, this is the setup for my autocomplete:

//The tags for autocompletebox on XAML

Second, my simple snippets:

//Event for the autocomplete to send a text string to my function
private void autoCompleteBox1_KeyUp(object sender, KeyEventArgs e)
{
autoCompleteBox1.Populating += (s, args) =>
{
args.Cancel = true;
var c = new Service1Client();
c.GetListByNameCompleted +=new EventHandler(c_GetListByNameCompleted);
c.GetListByNameAsync(autoCompleteBox1.Text);
};
}

//Getting result from database
void c_GetListByNameCompleted(object sender, GetListByNameCompletedEventArgs e)
{
autoCompleteBox1.ItemsSource = e.Result;
autoCompleteBox1.PopulateComplete();
}


The snippets above will show on how to use the autocompleteBox using the data from database that bind in DataGrid. But what if we want to show the result on DataGrid while the autocomplete changing the items source?

Ok just add one line to c_GetListByNameCompleted

void c_GetListByNameCompleted(object sender, GetListByNameCompletedEventArgs e)
{
autoCompleteBox1.ItemsSource = e.Result;
autoCompleteBox1.PopulateComplete();
dataGrid1.ItemsSource = e.Result;
}
 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Silverlight Simple DataGrid Binding

One Comment | Feb 28, 2010
Silverlight at Visual Studio 2010 sample for simple binding a data to DataGrid. This sample is also for the beginners only. We will create a Databinding for DataGrid in a simple way using WCF and Linq to SQL.
For more details:
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Draggable Image on Silverlight

One Comment | Feb 25, 2010

Hello Guys,

Early this morning I’m thinking about the draggable Image in Silverlight. I created a sample with simple snippets.

1. Create one Image, rectangle, and button.

2. Create an event handler for Image.


this.image1.MouseMove += new MouseEventHandler(image1_MouseMove);
this.image1.MouseLeftButtonDown += new MouseButtonEventHandler(image1_MouseLeftButtonDown);
this.image1.MouseLeftButtonUp += new MouseButtonEventHandler(image1_MouseLeftButtonUp);

3. Setting a variable
 
private bool isDragging = false; //dragging?
private Point mousePosition; //position of mouse

4. And now the events

void image1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
this.image1.ReleaseMouseCapture();
isDragging = false;
} //Release the mouse

void image1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
mousePosition = e.GetPosition(sender as UIElement);
this.image1.CaptureMouse();
isDragging = true;
} //Pressed the left mouse button

void image1_MouseMove(object sender, MouseEventArgs e)
{
if (isDragging)
{
this.imgTranslateTransform.X = e.GetPosition(this).X - mousePosition.X;
this.imgTranslateTransform.Y = e.GetPosition(this).Y - mousePosition.Y;
}
} //Dragging the Image

private void btnBrowse_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();

BitmapImage imgSrc = new BitmapImage();
imgSrc.SetSource(ofd.File.OpenRead());
image1.Source = imgSrc;
textBlock1.Text = "You can now drag the Image";
} // Open/Browsing the Image (binding Image)

http://silverlightsnippets.blogspot.com/

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Simple Encrypt and Decrypt on Silverlight

6 Comments | Feb 19, 2010
Hello Guys,
 
I have sample code here on how to create a simple encryption and decryption on Silverlight.
First, I created a PASSWORD from SL Controls. A Three Button for encryption, decryption, clear.
A one textblock and one textbox.
 
Second, I created a simple function for Encryption and Decryption and variables.
        
        byte[] _encryted;
        byte[] _decryted;
        string s;
 
        private string EncrytedString(string str)
        {
            _encryted = System.Text.Encoding.Unicode.GetBytes(str);
            s = Convert.ToBase64String(_encryted);
            return s;
        }
 
        private string DecrytedString(string str)
        {
            _decryted = Convert.FromBase64String(str);
s = System.Text.Encoding.Unicode.GetString(_decryted, 0,  _decryted.ToArray().Length);
            return s;
        }
 
 
Now the snippets.
 
            //For the Encryption Button
        private void btnEncrypt_Click(object sender, RoutedEventArgs e)
        {
            if (passwordBox1.Password == string.Empty)
            {
                MessageBox.Show("Please Enter your Password");
                passwordBox1.Focus();
            }
            else
            {
                btnDecrypt.IsEnabled = true;
                string s = EncrytedString(passwordBox1.Password);
                txtEncrypted.Text = s;
            }
 
        }
 
           //For the Decryption Button
        private void btnDecrypt_Click(object sender, RoutedEventArgs e)
        {
            string s;
            s = DecrytedString(txtEncrypted.Text);
            MessageBox.Show(s);
        }
 
       //For the Clear Button
        private void btnClear_Click(object sender, RoutedEventArgs e)
        {
            txtEncrypted.Text = string.Empty;
            passwordBox1.Password = string.Empty;
            passwordBox1.Focus();
            btnDecrypt.IsEnabled = false;
        }
 
 
 
 
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Simple CRUD on Visual Studio 2010

2 Comments | Nov 06, 2009

Hello Guys,

I have sample here on how to create a simple Create, Read, Update, and Delete on Database. This sample created on Visual Studio 2010 Beta 2 using C# and Asp.Net. I did'nt include a validation on this sample. I only want to show on how to Select, Insert, Update, Delete on Database. For those who beginners I hope it will help.

You can now download my Sample File at this Link.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Creating XML File on Visual Studio 2010

2 Comments | Nov 04, 2009

This code snippet will show you on how to create a simple xml file in Visual Studio 10 Beta 2.

Step 1: Add a namespace to your code behind System.Xml and System.Text

Step 2: In your event/method to create an xml file           

                //Create a path were to save the xml file

                String path = Server.MapPath(@”FolderName\MyFileName.xml”); 

                //Instantiate an XmlWriterSettings

                var xmlWrite = new XmlWriterSettings();

                //And other Declaration

                xmlWrite.Indent = true;

                xmlWrite.OmitXmlDeclaration = true;

                xmlWrite.Encoding = Encoding.ASCII;

                //Then try to write a data in xml file

                Using (var write = XmlWriter.Create(path,xmlWrite))

               {

                write.WriteComment(“This is a basic sample on how to create xml file”);

                write.WriteStartElement(“Head”);

                write.WriteStartElement(“Header”);

                write.WriteStartAttribute(“Header”);

                write.WriteValue(HeaderValue);

                write.WriteEndAttribute();

                write.WriteEndElement(); 

                write.WriteStartElement(“Footer”);

                write.WriteStartAttribute(“Footer”);

                write.WriteValue(FooterValue);

                 write.WriteEndAttribute();

                 write.WriteEndElement();

                 write.Flush();

                 }

That’s it. This sample created on asp.net project.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati