Click here to Skip to main content
15,885,214 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Call MVC controller method in SIlverlight with params Pin
Xodiak21-Jun-10 15:18
Xodiak21-Jun-10 15:18 
QuestionHow to send mail [Error: The SMTP server requires a secure connection or the client was not authenticated] Pin
Nekkantidivya1-Nov-09 19:24
Nekkantidivya1-Nov-09 19:24 
AnswerRe: How to send mail [Error: The SMTP server requires a secure connection or the client was not authenticated] Pin
Mark Salsbery2-Nov-09 8:44
Mark Salsbery2-Nov-09 8:44 
AnswerRe: How to send mail [Error: The SMTP server requires a secure connection or the client was not authenticated] Pin
earlgraham6-Nov-09 9:41
earlgraham6-Nov-09 9:41 
Questioncentering cursor and object Pin
sadas232341s1-Nov-09 7:57
sadas232341s1-Nov-09 7:57 
AnswerRe: centering cursor and object Pin
Mark Salsbery1-Nov-09 11:16
Mark Salsbery1-Nov-09 11:16 
GeneralRe: centering cursor and object Pin
sadas232341s1-Nov-09 20:17
sadas232341s1-Nov-09 20:17 
GeneralRe: centering cursor and object Pin
Mark Salsbery2-Nov-09 8:27
Mark Salsbery2-Nov-09 8:27 
TCPMem wrote:
That's exactly what I want. How can I make it?


First, I misread your code so I was wrong about how far off the cursor
was from the Canvas. I now see you're moving the entire canvas, not just
the rectangle, which is the way I read it Smile | :)

Anyway, here's a simple example that will hopefully get you going:
<Grid x:Name="LayoutRoot" Background="White">
    <Canvas Height="80" HorizontalAlignment="Left" Margin="100,100,0,0" VerticalAlignment="Top" Width="80"
            MouseLeftButtonUp="Canvas_MouseLeftButtonUp"
            MouseMove="Canvas_MouseMove"
            MouseLeftButtonDown="Canvas_MouseLeftButtonDown" >
        <Rectangle Fill="#FF80C1E4" Height="80" Width="80" RenderTransformOrigin="0.5,0.5" />
        <Rectangle Fill="#FF7AB7D8" Height="32" Width="32" Canvas.Left="24" Canvas.Top="24"/>
        <Canvas.RenderTransform>
            <TranslateTransform X="0" Y="0" x:Name="CanvasTransform"/>
        </Canvas.RenderTransform>
    </Canvas>
</Grid>

//protected override void OnMouseMove(MouseEventArgs e)
//{
//    base.OnMouseMove(e);

//    CanvasTransform.X = e.GetPosition(null).X;
//    CanvasTransform.Y = e.GetPosition(null).Y;
//}

Point anchorPoint;
bool isInDrag = false;

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

private void Canvas_MouseMove(object sender, MouseEventArgs e)
{
    if (isInDrag)
    {
        Point currentPoint = e.GetPosition(null);
        CanvasTransform.X = CanvasTransform.X + currentPoint.X - anchorPoint.X;
        CanvasTransform.Y = CanvasTransform.Y + currentPoint.Y - anchorPoint.Y;
        anchorPoint = currentPoint;
    }
}

private void Canvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    if (isInDrag)
    {
        FrameworkElement element = sender as FrameworkElement;
        element.ReleaseMouseCapture();
        isInDrag = false;
    }
}


Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

GeneralRe: centering cursor and object Pin
sadas232341s3-Nov-09 21:32
sadas232341s3-Nov-09 21:32 
QuestionHow can I determine if content fits control? Pin
fjparisIII31-Oct-09 16:01
fjparisIII31-Oct-09 16:01 
AnswerRe: How can I determine if content fits control? [modified] Pin
#realJSOP1-Nov-09 1:03
mve#realJSOP1-Nov-09 1:03 
GeneralRe: How can I determine if content fits control? Pin
fjparisIII1-Nov-09 4:40
fjparisIII1-Nov-09 4:40 
GeneralRe: How can I determine if content fits control? Pin
#realJSOP1-Nov-09 6:02
mve#realJSOP1-Nov-09 6:02 
GeneralRe: How can I determine if content fits control? Pin
fjparisIII1-Nov-09 6:40
fjparisIII1-Nov-09 6:40 
GeneralRe: How can I determine if content fits control? Pin
#realJSOP1-Nov-09 9:05
mve#realJSOP1-Nov-09 9:05 
GeneralRe: How can I determine if content fits control? Pin
fjparisIII1-Nov-09 9:57
fjparisIII1-Nov-09 9:57 
GeneralRe: How can I determine if content fits control? (Solved) Pin
fjparisIII1-Nov-09 10:41
fjparisIII1-Nov-09 10:41 
GeneralRe: How can I determine if content fits control? (Solved) Pin
#realJSOP1-Nov-09 23:09
mve#realJSOP1-Nov-09 23:09 
GeneralRe: How can I determine if content fits control? (Solved) Pin
#realJSOP2-Nov-09 0:04
mve#realJSOP2-Nov-09 0:04 
GeneralRe: How can I determine if content fits control? Pin
#realJSOP1-Nov-09 9:23
mve#realJSOP1-Nov-09 9:23 
QuestionMS RibbonBar Pin
#realJSOP30-Oct-09 12:48
mve#realJSOP30-Oct-09 12:48 
AnswerRe: MS RibbonBar Pin
Christian Graus30-Oct-09 14:07
protectorChristian Graus30-Oct-09 14:07 
GeneralRe: MS RibbonBar Pin
#realJSOP30-Oct-09 23:50
mve#realJSOP30-Oct-09 23:50 
AnswerRe: MS RibbonBar Pin
Mark Salsbery30-Oct-09 15:45
Mark Salsbery30-Oct-09 15:45 
GeneralRe: MS RibbonBar Pin
Christian Graus30-Oct-09 17:10
protectorChristian Graus30-Oct-09 17: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.