Friday 31 August 2012

Silverlight DataGrid DataBinding

Get Microsoft Silverlight

The XAML Code is as Follows



    
        
        
        
    




The CS code is as follows

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 grid
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

            List employeedetails = new List();

            employeedetails.Add(new data() { Name="Latha",ID="3456",Salary="12000" });
            employeedetails.Add(new data() { Name = "Geetha", ID = "3457", Salary = "13000" });
            employeedetails.Add(new data() { Name = "Mohan", ID = "3458", Salary = "14000" });
            employeedetails.Add(new data() { Name = "Ram", ID = "3459", Salary = "15000" });
            employeedetails.Add(new data() { Name = "Sundar", ID = "34570",Salary="16000" });

            dataGrid1.ItemsSource = employeedetails;
        }

        public class data
        {
            public string Name { get; set; }
            public string ID { get; set; }
            public string Salary { get; set; }
        }
       
    }
}


Thursday 16 August 2012

How to add Quick Launchbar in sharepoint Programatically


Step1

First you need to add the following name space

using Microsoft.SharePoint;
using Microsoft.SharePoint.Navigation;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.Publishing;

Step 2

And next include the following code in your web part

protected void Page_Load(object sender, EventArgs e)
        {
            using (var site = new SPSite(SPContext.Current.Site.Url))
            {
                var rootPubweb = PublishingWeb.GetPublishingWeb(site.RootWeb);
                var subwebs = rootPubweb.GetPublishingWebs();
                site.RootWeb.AllowUnsafeUpdates = true;

                string[] headnode = { "link1", "link2"};
                SPNavigationNodeCollection nodes =  site.RootWeb.Navigation.QuickLaunch;
                for (int j = 0; j < headnode.Length; j++)
                {
                    SPNavigationNode navNode = new SPNavigationNode(headnode[j], "http://www.google.com", false);
                    nodes.AddAsFirst(navNode);
                }
        }

Step 3


Finally deploy the web part. and insert the web part in your site& reload the page. this link will appear in your site.

Thursday 9 August 2012

Bing Map Latitude Longitude

Get Microsoft Silverlight

The  main  page cs code  for this  project  is  as follows

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 Microsoft.Maps;
using Microsoft.Maps.MapControl;

namespace slbng
{
    public partial class MainPage : UserControl
    {
       
        double x, y;
        Location location;
        public MainPage()
        {
            InitializeComponent();
           
        }
       
        private void BingMap_MouseMove(object sender, MouseEventArgs e)
        {
           x= e.GetPosition(BingMap).X;
           y = e.GetPosition(BingMap).Y;

           Point viewportpoint = e.GetPosition(BingMap);

           BingMap.TryViewportPointToLocation(viewportpoint, out location);
           LatTB.Text = location.Latitude.ToString();
           LongTB.Text = location.Longitude.ToString();
               
        }
    }
}


The  Xaml  code  for  the  project is as follows


    
        
        
            
            
            
            
         
    


Wednesday 8 August 2012

Silverlight Context Menu

Get Microsoft Silverlight



1) Create  an object of  context menu  class.

2)Create menu items copy and paste add it to the context menu.

3)Add the context menu object to the grid1.

4) On page load make the grid1 invisible so context menu will also become invisible.

5)Now we are going to handle the right click event of  LayoutRoot.
  •  we have given inside rightbuttondown event  "e.handled=true"  this is to remove the
       silverlight menu that appears on rightclick.
  •  Now for the  rightbuttonup event we are going to make our grid1 with context menu
       appear at the right clicked position



The  cs code for contextmenu  is as follows

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 contextmenu
{
    public partial class MainPage : UserControl
    {
        double a, b;
        
        public MainPage()
        {

            InitializeComponent();

            ContextMenu cm = new ContextMenu();
            cm.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            cm.VerticalAlignment = System.Windows.VerticalAlignment.Top;

            MenuItem copy = new MenuItem();
            copy.Header = "Copy";
            MenuItem paste = new MenuItem();
            paste.Header = "Paste";
            cm.Items.Add(copy);
            cm.Items.Add(paste);

            copy.Click += new RoutedEventHandler(copy_Click);
            paste.Click += new RoutedEventHandler(paste_Click);

            grid1.Children.Add(cm);
            grid1.Visibility = System.Windows.Visibility.Collapsed;

        }

        void paste_Click(object sender, RoutedEventArgs e)
        {
            grid1.Visibility = System.Windows.Visibility.Collapsed;
            MessageBox.Show("pasted");
        }

        private void copy_Click(object sender, RoutedEventArgs e)
        {
            grid1.Visibility = System.Windows.Visibility.Collapsed;
            MessageBox.Show("copied");
        }

        private void LayoutRoot_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            e.Handled = true;
        }

        private void LayoutRoot_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            a = e.GetPosition(LayoutRoot).X;
            b = e.GetPosition(LayoutRoot).Y; 
            grid1.Margin = new Thickness(a, b, 0, 0);
            grid1.Visibility = System.Windows.Visibility.Visible;  
        }

        private void LayoutRoot_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            grid1.Visibility = System.Windows.Visibility.Collapsed;
        }
    }
}


The XAML code for context menu is as follows