Click here to Skip to main content
15,891,431 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: XamlParseException showing a custom control Pin
RugbyLeague17-Sep-10 3:37
RugbyLeague17-Sep-10 3:37 
GeneralRe: XamlParseException showing a custom control Pin
Ian Shlasko17-Sep-10 3:37
Ian Shlasko17-Sep-10 3:37 
QuestionAsync threading with Silver-light Pin
1 316-Sep-10 18:34
1 316-Sep-10 18:34 
AnswerRe: Async threading with Silver-light [modified] Pin
#realJSOP16-Sep-10 23:43
mve#realJSOP16-Sep-10 23:43 
GeneralRe: Async threading with Silver-light Pin
1 317-Sep-10 2:04
1 317-Sep-10 2:04 
GeneralRe: Async threading with Silver-light Pin
1 317-Sep-10 2:10
1 317-Sep-10 2:10 
GeneralRe: Async threading with Silver-light Pin
#realJSOP17-Sep-10 2:42
mve#realJSOP17-Sep-10 2:42 
QuestionMoving control should stay within the bounds of the form? [modified] Pin
Jibrohni16-Sep-10 4:13
Jibrohni16-Sep-10 4:13 
Hi all. I've been gathering little bits of code from here, there and everywhere. I've got it doing what I want for the most part and just need someone's advice on the last part.

I have a button that moves it's position randomly when you trigger the Mouse Enter event. This works, but I want it to only move if the proposed position will be within the bounds of the control's form. Here's my code:

private void MoveControl(Control control, Window form)
        {
            TransformGroup tGroup = new TransformGroup();

            tGroup.Children.Add(new TranslateTransform(50.0, 50.0));
            control.RenderTransform = tGroup;

            DoubleAnimation dA_X = GenerateDoubleAnimation(-50, 50);
            DoubleAnimation dA_Y = GenerateDoubleAnimation(-50, 50);

            //Get the TranslateTransform for the rectangle (note Children[0], we added TranslateTransform first)
            TranslateTransform tt = (control.RenderTransform as TransformGroup).Children[0] as TranslateTransform;

            //Get the projected bounds of the control

            double dTop = Canvas.GetTop(control) + (double)dA_X.To;
            double dLeft = Canvas.GetLeft(control) + (double)dA_Y.To; 
            double dBottom = dTop + control.Height+ (double)dA_X.To;
            double dRight = dLeft+control.Width + (double)dA_Y.To;


            if (dTop > 0 && dLeft > 0 && dBottom < form.Height && dRight < form.Width)
            {
                tt.BeginAnimation(TranslateTransform.XProperty, dA_X);
                tt.BeginAnimation(TranslateTransform.YProperty, dA_Y);

                GeneralTransform myTrans = control.TransformToAncestor(this);
                Point p1 = myTrans.Transform(new Point(0, 0));

                control.SetValue(Canvas.LeftProperty, p1.X + dA_X.To);
                control.SetValue(Canvas.TopProperty, p1.Y + dA_Y.To);
            }
            else
            {
                MoveControl(control, form);
            }

        }
        DoubleAnimation GenerateDoubleAnimation(int min,int max)
        {
            DoubleAnimation da = new DoubleAnimation();
            
            //da.To = randomNumber.Next(min, max);
            da.To = randomNumber.Next(min, max);
            
            //da.AccelerationRatio = .8;
            //da.DecelerationRatio = .1;
            da.Duration = new Duration(TimeSpan.FromSeconds(.2));

            return da;
        }


I was hoping that this would prevent it moving outside of the form, but it doesn't. Also, I get an error with this line sometimes:

tGroup.Children.Add(new TranslateTransform(50.0, 50.0));

StackOverFlow error, that I don't understand.

Any pointers and help will be gratefully received.

Jib

modified on Friday, September 17, 2010 6:11 AM

QuestionHow do I tell why events aren't firing Pin
RugbyLeague16-Sep-10 2:49
RugbyLeague16-Sep-10 2:49 
AnswerRe: How do I tell why events aren't firing Pin
RugbyLeague16-Sep-10 5:42
RugbyLeague16-Sep-10 5:42 
GeneralRe: How do I tell why events aren't firing Pin
Pete O'Hanlon16-Sep-10 6:44
mvePete O'Hanlon16-Sep-10 6:44 
GeneralRe: How do I tell why events aren't firing Pin
RugbyLeague16-Sep-10 10:10
RugbyLeague16-Sep-10 10:10 
GeneralRe: How do I tell why events aren't firing Pin
Pete O'Hanlon16-Sep-10 10:13
mvePete O'Hanlon16-Sep-10 10:13 
QuestionRibbon Control - Workspace areas Pin
Sevententh14-Sep-10 23:16
Sevententh14-Sep-10 23:16 
QuestionRe: Ribbon Control - Workspace areas Pin
Sevententh15-Sep-10 0:25
Sevententh15-Sep-10 0:25 
QuestionWire up an event from a helper class Pin
Mycroft Holmes14-Sep-10 16:43
professionalMycroft Holmes14-Sep-10 16:43 
GeneralRe: Wire up an event from a helper class Pin
Mycroft Holmes15-Sep-10 12:08
professionalMycroft Holmes15-Sep-10 12:08 
QuestionEvents between user controls Pin
David_ml_G14-Sep-10 9:35
David_ml_G14-Sep-10 9:35 
AnswerRe: Events between user controls Pin
AspDotNetDev14-Sep-10 10:18
protectorAspDotNetDev14-Sep-10 10:18 
QuestionRe VS2003 error Pin
Ajay Kale New13-Sep-10 17:32
Ajay Kale New13-Sep-10 17:32 
AnswerRe: Re VS2003 error Pin
Pete O'Hanlon13-Sep-10 22:26
mvePete O'Hanlon13-Sep-10 22:26 
AnswerRe: Re VS2003 error Pin
Abhinav S19-Sep-10 19:57
Abhinav S19-Sep-10 19:57 
QuestionGetting the size of a control Pin
WebMaster13-Sep-10 9:47
WebMaster13-Sep-10 9:47 
QuestionRe: Getting the size of a control Pin
PumbaPumba27-Sep-10 6:44
PumbaPumba27-Sep-10 6:44 
QuestionMVVM and the ViewModelLocator Pin
Mycroft Holmes11-Sep-10 23:36
professionalMycroft Holmes11-Sep-10 23:36 

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.