Wednesday, December 19, 2012

Windows Phone Custom List

we can customize the list-box in our own way and purpose it is quite easy and simple, which is also easy to understand. we just need to take care the features and the libraries available to us. for this purpose
 just create a simple project with the name Lists ,now just follow the steps and see the magic :)

in this project make a folder with name images and put these imges inside this folder





1) just copy the given code to yours MainPage.xaml


<phone:PhoneApplicationPage 
    x:Class="Lists.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="800" 
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="False">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="#00E65BFF">

                <ListBox Margin="12,75,12,0" Name="L1"  SelectionChanged="ListBox_SelectionChanged" Foreground="#FF4AFFFF">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Margin="0,0,0,17" Width="432" Height="78">
                                <TextBlock  TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
                                <TextBlock  TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
                            
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
        <TextBlock Height="33" HorizontalAlignment="Left" Margin="12,36,0,0" Name="textBlock1" Text="Custom ListBoxes In windows Phone by Jitesh" VerticalAlignment="Top" Width="456" FlowDirection="LeftToRight" Grid.RowSpan="1" Foreground="#FF1685BB" AllowDrop="False" />
    </Grid>
</phone:PhoneApplicationPage>

2) in this step just copy the given code to yours 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;
using Microsoft.Phone.Controls;

namespace Lists
{
    public partial class MainPage : PhoneApplicationPage
    {
        
        // Constructor
        public MainPage()
        {
            List_row row=null;
            InitializeComponent();

            string[] arr1 = new string[] { "A", "B", "C","D", "E" };
            string[] sub = new string[] { "FIRST Alphabet", " SECOND Alphabet", "THIRD Alphabet", "FOURTH Alphabet", "FIFTH Alphabet" };
            string[] images = new string[] { "a", "b", "c", "d", "e" };

            for(int i = 0; i < arr1.Length ; ++i){
                 row = new List_row();             
                row.title.Text = arr1[i];
                row.sub.Text = sub[i];
                row.myimage.Source = (ImageSource)new ImageSourceConverter().ConvertFromString("images/" + images[i] + ".png");
                L1.Items.Add(row);

               
            }
           

            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
            
        }

        // Load data for the ViewModel Items
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
         
        }

        private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            
           
            MessageBox.Show("The selected index is : " + ((ListBox)sender).SelectedIndex);
        }

      
    }
}

3) in this third  step just create a new  .xaml with the name List_row.xaml

and  copy the code


<UserControl x:Class="Lists.List_row"
    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"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    d:DesignHeight="480" d:DesignWidth="319">

    <Grid x:Name="LayoutRoot" Height="60" Width="480"  MouseLeftButtonDown="Tap_LeftButtonDown"
                                      MouseLeave="Tap_MouseLeave" MouseLeftButtonUp="Tap_LeftButtonUp" Background="#FFC2B1CB">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="220*" />
            <ColumnDefinition Width="480*" />
        </Grid.ColumnDefinitions>
        <TextBlock Height="30" HorizontalAlignment="Left" Margin="66,6,0,0" Name="title" Text="TextBlock" VerticalAlignment="Top" Width="351" FontFamily="Times New Roman" Grid.ColumnSpan="2" Foreground="#FFBED700" />
        <Image Height="45" HorizontalAlignment="Left" Name="myimage" Stretch="Fill" VerticalAlignment="Top" Width="44" Margin="8,5,0,0" Source="/Lists;component/images/a.png" />
        <TextBlock Height="15" HorizontalAlignment="Left" Margin="67,33,0,0" Name="sub" Text="TextBlock" VerticalAlignment="Top" Width="384" FontSize="14" FontStyle="Normal" FontFamily="Times New Roman" Grid.ColumnSpan="2" Foreground="#FF36E3DD" />
    <Line X1="0" Y1="0" X2="1500" Y2="0" Stroke="#FFEF80FA" StrokeThickness="2" Grid.ColumnSpan="2" Margin="0,0,-2,0" />
    </Grid>
</UserControl>

4) in this step just copy this code to List_row.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 Lists
{
    public partial class List_row : UserControl
    {
        public List_row()
        {
            InitializeComponent();
        }
       
        private void Tap_LeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Grid rect = sender as Grid;
            // Change the size of the Rectangle.
            if (null != rect)
            {
                rect.Opacity = 0.5;
                SolidColorBrush color = new SolidColorBrush(Color.FromArgb(255, 0, 105, 0));
                rect.Background = color;


            }
        }
        private void Tap_LeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Grid rect = sender as Grid;
            // Reset the dimensions on the Rectangle.
            if (null != rect)
            {
                rect.Opacity = 1.0;
               
                SolidColorBrush color = new SolidColorBrush(Color.FromArgb(255, 194, 177, 203));
                rect.Background = color;

            }
        }
        private void Tap_MouseLeave(object sender, MouseEventArgs e)
        {
            Grid rect = sender as Grid;
            // Finger moved out of Rectangle before the mouse up event.
            // Reset the dimensions on the Rectangle.


            if (null != rect)
            {
                rect.Opacity = 1.0;
               
                SolidColorBrush color = new SolidColorBrush(Color.FromArgb(255, 194, 177, 203));
                rect.Background = color;

            }
        }
    }
}

finally you can see the desired output on yours emulator as follows




10 comments:

  1. Heya¡­my very first comment on your site. ,I have been reading your blog for a while and thought I would completely pop in and drop a friendly note. .
    Custom Application Development

    ReplyDelete
  2. I dO NOT KNOW WHO ARE YOU AND I THINK YOU ARE WRITING THE SAME STATEMENT OVER AND OVER. my mail id is upadhyay.jitesh@gmail.com

    ReplyDelete
  3. Windows application development includes the use of different systems and development languages suitable with the target cell phone. The different software structure employed will depend on the specific elements components in a particular cell phone. Application development for cell phones is particularly difficult because of the different consumer choices which call for comprehensive upgradation of traditional system growth procedures.

    Custom Application Development India

    ReplyDelete
  4. Really Nice blog. It is very healpful for me. Thank you for the launched manifest file and Thanks for the create contacts in Windows Phone 8. Visit this website More info.

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Hello my friend! I would like to tell you that this write-up is awesome, great written and include almost all important info. I would like to see a lot more articles like this.
    windows mobile apps development

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. Nice post. I learn something more challenging on different blogs everyday. It will always be stimulating to read content from other writers and practice a little something from their store. I’d prefer to use some with the content on my blog whether you don’t mind. Natually I’ll give you a link on your web blog. Thanks for sharing.
    custom website development company usa

    ReplyDelete
  9. This is a wonderful list of web development agencies. If you want to hire the best web development agency then go to this link-.Custom website development

    ReplyDelete
  10. I am a regular user of your post, this one also was very interesting and well written. keep sharing the great workWebsite Designing Company Bangalore | Web Development Company Bangalore

    ReplyDelete