Click here to Skip to main content
15,886,518 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: WPF event binding Pin
GomathiR17-Mar-09 21:52
GomathiR17-Mar-09 21:52 
GeneralRe: WPF event binding Pin
thangavel198717-Mar-09 22:53
thangavel198717-Mar-09 22:53 
GeneralRe: WPF event binding Pin
GomathiR18-Mar-09 18:19
GomathiR18-Mar-09 18:19 
AnswerRe: WPF event binding Pin
Ian Shlasko19-Mar-09 3:47
Ian Shlasko19-Mar-09 3:47 
QuestionHow to set the image inside a datagrid Pin
salon17-Mar-09 20:45
salon17-Mar-09 20:45 
AnswerRe: How to set the image inside a datagrid Pin
Mark Salsbery18-Mar-09 6:15
Mark Salsbery18-Mar-09 6:15 
Questionsilverlight Pin
Ch.Gayatri Subudhi17-Mar-09 20:08
Ch.Gayatri Subudhi17-Mar-09 20:08 
AnswerRe: silverlight Pin
Mark Salsbery18-Mar-09 6:22
Mark Salsbery18-Mar-09 6:22 
Here's a simple example of drag and drop. I used Rectangle objects here, but the same
principles apply to dragging and dropping any element...
<Grid x:Name="LayoutRoot" >
    <Canvas >
        <Rectangle Height="100" Width="100" Stroke="#FFFF0000" StrokeThickness="2" Fill="#00000000" Canvas.Top="42" Canvas.Left="44" MouseLeftButtonDown="Rectangle_MouseLeftButtonDown" MouseMove="Rectangle_MouseMove" MouseLeftButtonUp="Rectangle_MouseLeftButtonUp" />
        <Rectangle Height="100" Width="100" Stroke="#FFFF0000" StrokeThickness="2" Fill="#00000000" Canvas.Top="97" Canvas.Left="109" MouseLeftButtonDown="Rectangle_MouseLeftButtonDown" MouseMove="Rectangle_MouseMove" MouseLeftButtonUp="Rectangle_MouseLeftButtonUp" />
        <Rectangle Height="100" Width="100" Stroke="#FFFF0000" StrokeThickness="2" Fill="#00000000" Canvas.Top="145" Canvas.Left="169" MouseLeftButtonDown="Rectangle_MouseLeftButtonDown" MouseMove="Rectangle_MouseMove" MouseLeftButtonUp="Rectangle_MouseLeftButtonUp" />
    </Canvas>
</Grid>

Point anchorPoint;
Point currentPoint;
bool isInDrag = false;

private void Rectangle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    FrameworkElement anno = sender as FrameworkElement;
    anchorPoint = e.GetPosition(null);
    anno.CaptureMouse();
    isInDrag = true;
    e.Handled = true;
}

private void Rectangle_MouseMove(object sender, MouseEventArgs e)
{
    if (isInDrag)
    {
        FrameworkElement anno = sender as FrameworkElement;
        currentPoint = e.GetPosition(null);
        double x = System.Convert.ToDouble(anno.GetValue(Canvas.LeftProperty));
        double y = System.Convert.ToDouble(anno.GetValue(Canvas.TopProperty));
        anno.SetValue(Canvas.LeftProperty, x + currentPoint.X - anchorPoint.X);
        anno.SetValue(Canvas.TopProperty, y + currentPoint.Y - anchorPoint.Y);
        anchorPoint = currentPoint;
    }
}

private void Rectangle_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    if (isInDrag)
    {
        FrameworkElement anno = sender as FrameworkElement;
        anno.ReleaseMouseCapture();
        isInDrag = false;
        e.Handled = true;
    }
}


Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

GeneralRe: silverlight Pin
Ch.Gayatri Subudhi19-Mar-09 19:03
Ch.Gayatri Subudhi19-Mar-09 19:03 
QuestionTrigger Blend Storyboard from code behind. Pin
emptythetill17-Mar-09 9:52
emptythetill17-Mar-09 9:52 
AnswerRe: Trigger Blend Storyboard from code behind. Pin
Pete O'Hanlon17-Mar-09 10:22
mvePete O'Hanlon17-Mar-09 10:22 
GeneralRe: Trigger Blend Storyboard from code behind. Pin
emptythetill17-Mar-09 11:13
emptythetill17-Mar-09 11:13 
GeneralRe: Trigger Blend Storyboard from code behind. Pin
Pete O'Hanlon17-Mar-09 11:16
mvePete O'Hanlon17-Mar-09 11:16 
GeneralRe: Trigger Blend Storyboard from code behind. Pin
emptythetill17-Mar-09 11:36
emptythetill17-Mar-09 11:36 
GeneralRe: Trigger Blend Storyboard from code behind. Pin
Pete O'Hanlon17-Mar-09 11:41
mvePete O'Hanlon17-Mar-09 11:41 
QuestionValue Converter Work Around For Data Validation Pin
BlitzPackage17-Mar-09 5:11
BlitzPackage17-Mar-09 5:11 
AnswerRe: Value Converter Work Around For Data Validation Pin
Pete O'Hanlon17-Mar-09 5:52
mvePete O'Hanlon17-Mar-09 5:52 
GeneralRe: Value Converter Work Around For Data Validation Pin
BlitzPackage17-Mar-09 6:36
BlitzPackage17-Mar-09 6:36 
QuestionHow to set the background color of a particluar column in Silverlight? Pin
salon17-Mar-09 3:38
salon17-Mar-09 3:38 
QuestionWooHoo!!! Pin
Jammer17-Mar-09 2:49
Jammer17-Mar-09 2:49 
AnswerRe: WooHoo!!! Pin
Pete O'Hanlon17-Mar-09 3:00
mvePete O'Hanlon17-Mar-09 3:00 
GeneralRe: WooHoo!!! Pin
Jammer17-Mar-09 3:03
Jammer17-Mar-09 3:03 
QuestionSilverlight Pin
Ch.Gayatri Subudhi16-Mar-09 22:35
Ch.Gayatri Subudhi16-Mar-09 22:35 
AnswerRe: Silverlight Pin
Mark Salsbery17-Mar-09 10:13
Mark Salsbery17-Mar-09 10:13 
GeneralSilverlight Pin
Ch.Gayatri Subudhi17-Mar-09 18:10
Ch.Gayatri Subudhi17-Mar-09 18:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.