flotable Window demo

Wednesday, June 30, 2010

In Silverlight beta Microsoft provide us a Control called Childwindow.


Childwindow it just like we use Midi form in Desktop Windows Application or child form in base form window or you can say that Multiple form in one page but when we use silver-light ChildWindow Control it disable the parent Form. thats mean`s you can not work on parent form before close child-windows and you can not open Multiple child window in parent page to use them like flotable Windows or panels.ChildWindow has to be the top-most element in the Xaml. thats why its always on top and disable all parent controls .silverlight provide us another control for popup its called Popup Control so i just add ChildWindow in Popup as Child and open and close the popup thats i got base and beautiful functionality Childwindow like Floating ,dialog and i can interact with parent form as well or open Multiple childwindows in one form


 



 



<UserControl x:Class="SilverlightFlotingChildWindow.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" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"



>



<Canvas x:Name="LayoutRoot" Background="White" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">



<Button Content="Window 1" Height="23" HorizontalAlignment="Left" Margin="59,270,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />



<Button Content="Window 2" Height="23" HorizontalAlignment="Left" Margin="140,270,0,0" Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click" />



<Button Content="Window 3" Height="23" HorizontalAlignment="Left" Margin="221,270,0,0" Name="button3" VerticalAlignment="Top" Width="75" Click="button3_Click" />


</Canvas>

</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 SilverlightFlotingChildWindow

{


public partial class MainPage : UserControl

{


public MainPage()

{



InitializeComponent();



}



 


private void button1_Click(object sender, RoutedEventArgs e)

{


ChildWindow flotwin =
new ChildWindow();flotwin.Title = "Blue Window";

 


System.Windows.Controls.Primitives.Popup popup =
new System.Windows.Controls.Primitives.Popup();

 



flotwin.MouseLeftButtonDown += (a, x) =>



{


this.LayoutRoot.Children.Remove(popup);

this.LayoutRoot.Children.Add(popup);


popup.IsOpen =
true;

};



 


flotwin.Content =
new StackPanel()

{


Background =
new SolidColorBrush(Colors.Blue),

Height = 300,



Width = 300



};



flotwin.Closing +=(ss,ee)=>



{


popup.IsOpen =
false;

};



popup.Child = flotwin;


popup.IsOpen =
true;

 



 



 



LayoutRoot.Children.Add(popup);



}


private void button2_Click(object sender, RoutedEventArgs e)

{


ChildWindow flotwin =
new ChildWindow();

flotwin.Title = "Orange Window";


System.Windows.Controls.Primitives.Popup popup =
new System.Windows.Controls.Primitives.Popup();

 



flotwin.MouseLeftButtonDown += (a, x) =>



{


this.LayoutRoot.Children.Remove(popup);

this.LayoutRoot.Children.Add(popup);


popup.IsOpen =
true;

};


flotwin.Content =
new StackPanel()

{


Background =
new SolidColorBrush(Colors.Orange),

Height = 300,



Width = 300



};



flotwin.Closing += (ss, ee) =>



{


popup.IsOpen =
false;

};



popup.Child = flotwin;


popup.IsOpen =
true;

LayoutRoot.Children.Add(popup);



}


private void button3_Click(object sender, RoutedEventArgs e)

{


ChildWindow flotwin =
new ChildWindow();

 


flotwin.Title =
"Purple Window";System.Windows.Controls.Primitives.Popup popup = new System.Windows.Controls.Primitives.Popup();

 



flotwin.MouseLeftButtonDown += (a, x) =>



{


this.LayoutRoot.Children.Remove(popup);

this.LayoutRoot.Children.Add(popup);


popup.IsOpen =
true;

};


flotwin.Content =
new StackPanel()

{


Background =
new SolidColorBrush(Colors.Purple),

Height = 300,



Width = 300



};



flotwin.Closing += (ss, ee) =>



{


popup.IsOpen =
false;

};



popup.Child = flotwin;


popup.IsOpen =
true;

LayoutRoot.Children.Add(popup);



}



}





Download Source Code


Entity Framework with Linq CRUD Operation Example

Friday, June 25, 2010

Download Tutorial


Download Source Code

Usama Wahab KHan

Asp.net Server Side State Management

Wednesday, June 23, 2010


No web application framework, no matter how advanced, can change that HTTP is a stateless protocol. So inherently we should also forget our users, but unfortunately we cannot.ASP.Net Framework provides us features by which we can maintain states of your users. We can Manage State on Application ans Session Level
  • Session State
  • Application State
Session State:
It stores user specific information on server side.
There are 5 modes which a user can define for Session States;
  1. Off

  1. InProc

  1. StateServer

  1. SQLServer
  1. Custom
Sessions can and can not be cookie based.
The default name for this Session based cookie is Asp.Ner_SessionId We

Session state is structured as a key/value dictionary for storing session-specific information that needs to be maintained between server round trips and between requests for pages.
You can use session state to accomplish the following tasks:

Uniquely identify browser or client-device requests and map them to an individual session instance on the server.

Store session-specific data on the server for use across multiple browser or client-device requests within the same session.

Raise appropriate session management events. In addition, you can write application code leveraging these events

Sessions (In Proc)
When the configuration is set to InProc, session data is stored in the HTTPRuntime’s internal cache in an implementation of ISessionItemCollection that implements ICollection.
Stores Session in ASP.Net in-memory cache.


Sessions (State Server)
Also known as out of process.
Sessions states are held in a process called aspnet_state.exe that runs as a Windows Service.
Objects to be stored in StateServer sessions requires to be Serializable.
By default State Service is not running.

timeout=“20”/>
>
Sessions (Sql Server)
Sql Server based state management is not effected by farming or gardening issues.
Enable Sql Server support by running aspnet regsql -? Command to access and enable Session State Option.
Aspnet_regsql –S machine\servername –d statemanagement –U sa –P new –ssadd –sstype c
Sessions Recommendations
  • InProc is the fastest but most unreliable
  • StateServer is a better option but requires Serialization. It is slower than InProc as objects physically leave the application.
  • SQLServer is the most reliable and robust but is the slowest but also helpful when it comes to application scalability.
Declaring a Session Variable



string firstName = "Usama";
string lastName = "Khan";
string city = "Karachi";
Session["FirstName"] = firstName;
Session["LastName"] = lastName;
Session["City"] = city;
Using Session Variable




TxtfirstName
.Text
=
Session["FirstName"];
Txt
lastName
.Text
=
Session["LastName"]
;
Txt
city.Text =
Session["City"]
;

Application State
Application state is a data repository available to all classes in an ASP.NET application. Application state is stored in memory on the server and is faster than storing and retrieving information in a database. Unlike session state, which is specific to a single user session, application state applies to all users and sessions. Therefore, application state is a useful place to store small amounts of often-used data that does not change from one user to another
Global does not mean global to the machine, but global to the application.
Look for global.asax file.

Application state is stored in an instance of the HttpApplicationState class. This class exposes a key-value dictionary of objects.

Declaring Application Variable

In Application_Start handler of your application's Global.asax

Application["Message"] = "Welcome to Evolution Technologies ";

Application["PageRequestCount"] = 0;

Application.Lock();

Application["PageRequestCount"] =

((int)Application["PageRequestCount"])+1;

Application.UnLock();


Three Days Multi-Touch Training Session At MIC

Friday, June 18, 2010








Microsoft Pakistan has arranged a technical training camp on Windows 7 Multi-Touch platform to develop application’s using WPF and Silverlight 4.

Trainer:
Ali Khawaja
Principal Consultant at Microsoft
logo_82x23

Training Camp Outline
Day – 1

Track #Description
1

Introduction to Multi Touch

2-aIntroduction to WPF & Silverlight 4
2-bIntroduction to WPF & Silverlight 4 Lab
3-aMultitouch (Basics of Windows 7 Multitouch and its APIs)

3-b

Multitouch Lab
4-aDrag and Drop, Printing, and Multi-touch in Silverlight
4-bDrag and Drop, Printing, and Multi-touch in Silverlight Lab

Day – 2

Track #Description
1-aWPF/Silverlight Validation, Binding, DataForm and DataGrid
1-bWPF/Silverlight Validation, Binding, DataForm and DataGrid Lab

2

Implementing a Scenario using Multi Touch
3-aRibbon (Different aspects of the Windows 7 Ribbon and how to incorporate the Windows 7 Ribbon into existing applications.)
3-bRibbon Lab

Microsoft Also Arranged a contest on Multi-Touch Application Development and i won that and got dinar 100 and its Was such a great experience and Trainer was such help . I like to Thanks Microsoft Arranged this kinda event in Pakistan such a great effort by mic ,Noman Sohai,Jibran Jamsha,Talha Mahmood,Naveed bajwa and etl
and Special thank to Ali Khawaja visiting Pakistan


SILVERLIGHT COM AUTOMATION iterative Excel

Tuesday, June 15, 2010

SilverLight Support COM AUTOMATION in out of the browser mode. its a wonderful capability by using COM AUTOMATION on web. by using COM AUTOMATION in silver light interact with other application as well like Microsoft Office (Excel,Word,other..) excel is great to generate Reports in Silver light. so there demo with source code i get help form windows application to create this excel interaction for write function in c#sharep because we have to use dynamic DataType which has been provided in . net-framework 4 dynamic datatype initialize on runtime thats why it do not provide intelligence.

Xaml Code

<UserControl x:Class="LoadExcelObjects.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="600" d:DesignWidth="400" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">

<Grid x:Name="LayoutRoot" Background="White">

<Image Height="215" HorizontalAlignment="Left" Margin="0,44,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="400" />

<Button Content="Create" Height="23" HorizontalAlignment="Left" Margin="28,15,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />

<Button Content="Load" Height="23" HorizontalAlignment="Left" Margin="313,49,0,0" Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click" />

<sdk:DataGrid AutoGenerateColumns="True" Height="196" HorizontalAlignment="Left" Margin="-8,262,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="408" />

<Button Height="28" HorizontalAlignment="Left" Margin="109,15,0,0" Name="button23" VerticalAlignment="Top" Width="279" Content="Kindly install this Applicaiton then Run" Click="label1_Click" />

Grid>

UserControl>


Csharep Code


public partial class MainPage : UserControl

{

dynamic excel;

dynamic sheetShapes;

dynamic chart;

dynamic sheet;

public MainPage()

{

InitializeComponent();

this.Loaded += new RoutedEventHandler(MainPage_Loaded);

}

void MainPage_Loaded(object sender, RoutedEventArgs e)

{

if (Application.Current.InstallState == InstallState.NotInstalled)

{

button1.IsEnabled = false;

button2.IsEnabled = false;

}

else

{

button1.IsEnabled = true;

button2.IsEnabled = true;

}

}

private void button1_Click(object sender, RoutedEventArgs e)

{

if (AutomationFactory.IsAvailable)

{

excel = AutomationFactory.CreateObject("Excel.Application");

excel.Visible = true;

excel.Workbooks.Add();

dynamic workbook = excel.workbooks;

sheet = excel.ActiveSheet; // get the active sheet

dynamic cell = null;

int i = 1;

List<UsamastudentDatatype> data = new List<UsamastudentDatatype>();

for (int j = 0; j <>

{

data.Add(new UsamastudentDatatype() { Subject = "ASP.NET", Marks = (10 + j).ToString(), Name = "Students" });

}

foreach (var item in data)

{

cell = sheet.Cells[i, 1]; // row, column

cell.Value = item.Name;

cell.ColumnWidth = 25;

cell = sheet.Cells[i, 2];

cell.Value = item.Subject;

cell = sheet.Cells[i, 3];

cell.Value = item.Marks;

i++;

}

// add a chart

sheetShapes = sheet.Shapes;

sheetShapes.AddChart(-4100, 200, 2, 400, 300);

chart = sheet.ChartObjects(1).Chart;

}

}

private void button2_Click(object sender, RoutedEventArgs e)

{

if (AutomationFactory.IsAvailable)

{

string path = string.Format("{0}\\picture.jpg",

Environment.GetFolderPath(Environment.SpecialFolder.MyPictures));

chart.Export(path, "JPG");

try

{

using (FileStream stream = File.OpenRead(path))

{

BitmapImage bitmapImage = new BitmapImage();

bitmapImage.SetSource(stream);

image1.Source = bitmapImage;

stream.Close();

}

}

catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); }

loadgrid();

}

}

void loadgrid()

{

List<UsamastudentDatatype> obj = new List<UsamastudentDatatype>();

try

{

for (dynamic i = 1; i <>

{

UsamastudentDatatype rowobject = new UsamastudentDatatype();

rowobject.Marks = excel.ActiveSheet.Cells[i, 2].Value.ToString();

rowobject.Name = excel.ActiveSheet.Cells[i, 1].Value.ToString();

rowobject.Subject = excel.ActiveSheet.Cells[i, 2].Value.ToString();

obj.Add(rowobject);

}

}

catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); }

dataGrid1.ItemsSource = obj;

}

private void label1_Click(object sender, RoutedEventArgs e)

{

if (Application.Current.InstallState == InstallState.NotInstalled)

{

Application.Current.Install();

}

else

{

button23.IsEnabled = false;

}

}

}

public class UsamastudentDatatype

{

public string Name { get; set; }

public string Subject { get; set; }

public string Marks { get; set; }

}



Download Source

By Usama Wahab khan