Tuesday, August 10, 2010

FluidMoveBehavior


Learn to create applications that change layout and visual appearance using smooth, dynamic and visually rich transitions without writing code. Come see new features in Expression Blend that raise the bar, making it even easier to create amazing applications that will delight users

Tuesday, May 18, 2010

custom drag drop in silverlight

custom drag drop in silverlight
#region custom Drag Drop

double _horizDrag = 0;
double _vertDrag = 0;
double _mouseVerticalPosition;
double _mouseHorizontalPosition;
bool _captured = false;
bool _isDragStart = false;
private void EndDragPopupMouseLeftUp()
{

_horizDrag = _vertDrag = 0;
_captured = false;
popupContent.Content = null;
popupContent.ContentTemplate = null;
//popup1.ReleaseMouseCapture();
_mouseVerticalPosition = -1;
_mouseHorizontalPosition = -1;
var ts = new ThreadStart(DragHold);
// create new thread
var thrd = new Thread(ts);
// start thread
thrd.Start();
}
public void DragHold()
{
// makes the main thread sleep - let sub thread to run
Thread.Sleep(100);
//if (!IsOver)
_isDragStart = false;
}
private void MoveDragPopupMouseMove(MouseEventArgs e)
{
if (_captured)
{

// Calculate the current position of the object.
double deltaV = e.GetPosition(null).Y - _mouseVerticalPosition;
double deltaH = e.GetPosition(null).X - _mouseHorizontalPosition;
_horizDrag += deltaH;
_vertDrag += deltaV;
double newTop = deltaV + (double)popup1.VerticalOffset;
double newLeft = deltaH + (double)popup1.HorizontalOffset;

// Set new position of object.
popup1.VerticalOffset = newTop;
popup1.HorizontalOffset = newLeft;


// Update position global variables.
_mouseVerticalPosition = e.GetPosition(null).Y;
_mouseHorizontalPosition = e.GetPosition(null).X;
var temBor = popupContent.Content as Border;
var lbl = temBor.Child as Label;
lbl.Content = "Selected to Drop (X=" + _mouseVerticalPosition + ",Y=" + _mouseHorizontalPosition + ")";
}
}
private void StartDragMouseLeftDown(MouseEventArgs e,object tag)
{
Thread.Sleep(350);

var myEffect = new DropShadowEffect
{
Color = Colors.Black,
BlurRadius = 5,
Direction = 280,
Opacity = 0.7,
ShadowDepth = 5,
};

var borde = new Border
{
BorderThickness = new Thickness(2),
BorderBrush = new SolidColorBrush(Colors.White),
Effect = myEffect,
Opacity = .7,
Tag = tag,
};
var lbl = new Label
{
Content = "Selected to Drop",
Foreground = new SolidColorBrush(Colors.Blue),
Background = new SolidColorBrush(Colors.DarkGray),
//BorderBrush = new SolidColorBrush(Colors.Orange),
BorderThickness = new Thickness(0)
};

borde.Child = lbl;
popupContent.Content = borde;
//popup1.CaptureMouse();
_captured = true;
_mouseVerticalPosition = e.GetPosition(null).Y;
_mouseHorizontalPosition = e.GetPosition(null).X;
popup1.HorizontalOffset = _mouseHorizontalPosition;
popup1.VerticalOffset = _mouseVerticalPosition;
_isDragStart = true;
}
private void GetDragDropElement()
{
if (_isDragStart)
{
MessageBox.Show("dropd on me");
_isDragStart = false;
}

}
//on .xaml file
/*
*/
#endregion

Tuesday, April 20, 2010

Get parent type Object ex. in treeview

void method
{
// calling the method
TreeViewItem trvItem = GetParentTreeViewItem((DependencyObject)sender);
}
// this will return the desire type exg. here it is returning TreeViewItem type..
private static TreeViewItem GetParentTreeViewItem(DependencyObject item)
{

if (item != null)
{
DependencyObject parent = VisualTreeHelper.GetParent(item);
TreeViewItem parentTreeViewItem = parent as TreeViewItem;
return (parentTreeViewItem != null) ? parentTreeViewItem : GetParentTreeViewItem(parent);
}
return null;

}

Monday, April 12, 2010

Get xml from web services and use in tree view of silver light

private void cmbTaxonomy_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
_objWebService.getTreeOfClassCompleted += new EventHandler(_objWebService_getTreeOfClassCompleted);
_objWebService.getTreeOfClassAsync(cmbTaxonomy.SelectedItem.ToString());
}
const string xmlNodeTextAttName = "Name";
const string xmlNodeTagAttId = "Id";
const string xmlNodeTagClass = "Class";
const string xmlNodeTagRoot = "Root";
void _objWebService_getTreeOfClassCompleted(object sender, getTreeOfClassCompletedEventArgs e)
{
XDocument xDocument = XDocument.Parse(e.Result);
trvHierarchy.Items.Clear();
if (xDocument.Root != null)
if(xDocument.Root.Elements().ToArray().Count()>0)
{
foreach (var VARIABLE in xDocument.Root.Elements().ToArray())
{
if (VARIABLE != null)
{
TreeViewItem parentNodeItem = new TreeViewItem
{
IsExpanded = true,
Header = CreateTreeViewItemHeader(VARIABLE.Attribute(xmlNodeTextAttName).Value, Convert.ToInt64(VARIABLE.Attribute(xmlNodeTagAttId).Value))
};
AddChildItemsInTree(VARIABLE, parentNodeItem);
trvHierarchy.Items.Add(parentNodeItem);
}

}
}
}

private void AddChildItemsInTree(XElement ParentVariable, TreeViewItem parentNodeItem)
{
if(ParentVariable.HasElements)
{
foreach(var variableChild in ParentVariable.Elements().ToArray())
{
if (ParentVariable != null)
{
TreeViewItem childNodeItem = new TreeViewItem
{
IsExpanded = true,
Header = CreateTreeViewItemHeader(variableChild.Attribute(xmlNodeTextAttName).Value, Convert.ToInt64(variableChild.Attribute(xmlNodeTagAttId).Value))
};
//childNodeItem.Header = variableChild.Attribute(xmlNodeTextAttName).Value;
AddChildItemsInTree(variableChild, childNodeItem);
parentNodeItem.Items.Add(childNodeItem);
}
}
}
}

Creat xml for web services and return it

public string getTreeOfClass(string taxonomyName)
{
//get ClassElementsName
var taxsonomyId = _exhibitDb.Taxonomies.SingleOrDefault(o => o.Taxonomy1 == taxonomyName);

var classeList = from c in _exhibitDb.Classes join tc in _exhibitDb.TaxonomyClasses on c.ID equals tc.ClassID where (tc.TaxonomyID.Equals(taxsonomyId.ID)) select c;
//XDocument document = new XDocument();
//document.Root
const string xmlNodeTextAttName = "Name";
const string xmlNodeTagAttId = "Id";
const string xmlNodeTagClass = "Class";
const string xmlNodeTagRoot = "Root";
XmlWriterSettings settings = new XmlWriterSettings
{
Indent = true,
OmitXmlDeclaration = true,
NewLineOnAttributes = false,
Encoding = Encoding.UTF8
};
StringBuilder sb = new StringBuilder();
XmlWriter writer = XmlWriter.Create(sb, settings);
//writing xml

if (writer != null)
{
writer.WriteStartDocument();
writer.WriteStartElement(xmlNodeTagRoot);
foreach (var v in classeList)
{
writer.WriteStartElement(xmlNodeTagClass);
writer.WriteAttributeString(xmlNodeTextAttName, v.Class1);
writer.WriteAttributeString(xmlNodeTagAttId, v.ID.ToString());
AddChildElement(writer, v.ID, xmlNodeTagAttId, xmlNodeTextAttName, xmlNodeTagClass);
writer.WriteEndElement();
}

writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
}
return sb.ToString();// xmlDocument;
}

Friday, July 10, 2009

crrating csv in c# and asp.net

public void getHBRemindercsvFile()
{
if(dsBdayReminder.Tables[0].Rows.Count<1)
{
LblError.Visible=true;
LblError.Text="You have no reminders !";
}
string attachment = "attachment; filename=BirthdayReminder.csv";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("content-disposition", attachment);
HttpContext.Current.Response.ContentType = "text/csv";
HttpContext.Current.Response.AddHeader("Pragma", "public");
WriteColumnName(" Name , Day , Month ");
foreach (DataRow drt in dsBdayReminder.Tables[0].Rows)
{
WriteHBReminder(drt);
}

HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
private void WriteHBReminder(DataRow drt)
{
StringBuilder stringBuilder = new StringBuilder();

AddComma(drt["reminder_name"].ToString(), stringBuilder);
AddComma(drt["reminder_day"].ToString(), stringBuilder);
AddComma(GetMonthName(Convert.ToInt32(drt["reminder_month"])), stringBuilder);

HttpContext.Current.Response.Write(stringBuilder.ToString());
HttpContext.Current.Response.Write(Environment.NewLine);
}

private void AddComma(string value, StringBuilder stringBuilder)
{
stringBuilder.Append(value.Replace(',', ' '));
stringBuilder.Append(", ");
}

private void WriteColumnName(string columnNames)
{
HttpContext.Current.Response.Write(columnNames);
HttpContext.Current.Response.Write(Environment.NewLine);
}

making thumbnil in asp.net

public class MakeThumbnail : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// get the file name -- fall800.jpg
string file = Request.QueryString["file"];

// create an image object, using the filename we just retrieved
System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(file));

// create the actual thumbnail image
System.Drawing.Image thumbnailImage = image.GetThumbnailImage(160, 120, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);

// make a memory stream to work with the image bytes
MemoryStream imageStream = new MemoryStream();

// put the image into the memory stream
thumbnailImage.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg);//Imaging.Imageformat.Jpeg);

// make byte array the same size as the image
byte[] imageContent = new Byte[imageStream.Length];

// rewind the memory stream
imageStream.Position = 0;

// load the byte array with the image
imageStream.Read(imageContent, 0, (int)imageStream.Length);

// return byte array to caller with image type
Response.ContentType = "image/jpeg";
Response.BinaryWrite(imageContent);
}
public bool ThumbnailCallback()
{
return true;
}

HTML tag
img src='wallpaper/MakeThumbnail.aspx?file=<%# DataBinder.Eval(Container.DataItem,"image_path") %>'