Software & Finance





Silverlight Control for sorting numbers





 

Here is the Silverlight Control Source code Sorting Numbers given below:

 

<UserControl x:Class="SortNumbers.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    d:DesignHeight="350" d:DesignWidth="400">

 

    <Grid x:Name="LayoutRoot" Background="#eeeeee">

        <Grid.RowDefinitions>

            <RowDefinition Height="40"></RowDefinition>

            <RowDefinition Height="300"></RowDefinition>

        </Grid.RowDefinitions>

 

           

            <TextBox Grid.Row="0" HorizontalAlignment="Left" Margin="10,10,0,0" Name="TextBox1" Width="100" Height="25"></TextBox>

            <Button Grid.Row="0" HorizontalAlignment="Left" Margin="114,10,0,0" Click="Add_Click" Content="Add" Width="50" Height="25"></Button>

        <Button Grid.Row="0" HorizontalAlignment="Left" Margin="180,10,0,0" Click="Clear_Click" Content="Clear" Width="50" Height="25"></Button>

        <Button Grid.Row="0" HorizontalAlignment="Left" Margin="240,10,0,0" Click="Sort_Click" Content="Sort" Width="50" Height="25"></Button>

 

            <ListBox Grid.Row="1"  HorizontalAlignment="Left" Name="inplistbox" Margin="10,10,0,0"  Width="150" Height="200" VerticalAlignment="Top">

            </ListBox>

        <ListBox Grid.Row="1"  HorizontalAlignment="Left" Name="outlistbox" Margin="210,10,0,0"  Width="150" Height="200" VerticalAlignment="Top">

        </ListBox>

 

    </Grid>

</UserControl>

 

 

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 SortNumbers

{

    public partial class MainPage : UserControl

    {

        public MainPage()

        {

            InitializeComponent();

            inplistbox.Items.Add(100);

            inplistbox.Items.Add(400);

            inplistbox.Items.Add(300);

            inplistbox.Items.Add(500);

            inplistbox.Items.Add(200);

        }

 

        private void Add_Click(object sender, RoutedEventArgs e)

        {

            string inpstr = TextBox1.Text;

            Decimal d =  Convert.ToDecimal(inpstr);

            inplistbox.Items.Add(d.ToString());

        }

 

        private void Sort_Click(object sender, RoutedEventArgs e)

        {

            List<Decimal> arrList = new List<decimal>();

 

            for (int i = 0; i < inplistbox.Items.Count; i++)

                arrList.Add(Convert.ToDecimal(inplistbox.Items[i]));

 

            for (int i = 0; i < arrList.Count(); i++)

            {

                for (int j = 0; j < arrList.Count() - 1 - i; j++)

                {

                    if (arrList[j] > arrList[j+1])

                    {

                        Decimal temp = arrList[j];

                        arrList[j] = arrList[j+1];

                        arrList[j+1] = temp;

                    }

                }

            }

            outlistbox.Items.Clear();

            for (int i = 0; i < arrList.Count(); i++)

            {

                outlistbox.Items.Add(arrList[i].ToString());

            }

        }

 

        private void Clear_Click(object sender, RoutedEventArgs e)

        {

            inplistbox.Items.Clear();

            outlistbox.Items.Clear();

        }

    }

}

 

 

Here is the hosting source code in HTML tag

 

<body>

    <form id="form1" runat="server" style="height:100%">

    <div id="silverlightControlHost">

        <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">

                <param name="source" value="SortNumbers.xap"/>

                <param name="onError" value="onSilverlightError" />

                <param name="background" value="white" />

                <param name="minRuntimeVersion" value="3.0.40818.0" />

                <param name="autoUpgrade" value="true" />

                <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40818.0" style="text-decoration:none">

                       <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/>

                </a>

           </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>

    </form>

</body>

 

 

 

Click here to access the hosting page of this control