• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

WPF a step backwards in some ways

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    WPF a step backwards in some ways

    HTF do you get the topleft coords of a UI element?

    I got this code
    Code:
        GeneralTransform objGeneralTransform = myObj.TransformToVisual(Application.Current.RootVisual as UIElement);
          Point point = objGeneralTransform.Transform(new Point(0, 0));
          double myObjTop = point.Y;
          double myObjLeft = point.X;
    after a bit of googling but it doesn't recognise Application.Current.RootVisual

    In the good old days of hwnds and windows api this was a piece of piss, even windows forms has properties for top and left.
    Knock first as I might be balancing my chakras.

    #2
    Out of idle curiosity I went to have a look through the WPF documentation at http://msdn.microsoft.com/library but it was impossible to find.

    A Google search uncovered it at the URL http://msdn.microsoft.com/en-gb/library/ms754130.aspx - I really should have guessed that it would come under the name 754130, I suppose.

    On the offchance that I might still be able to help, I scanned the available resources and had a look at "Layout System" (as mere n00bs like myself call it - a MSMaven would of course know that its real name is 745058). This eventually led me to some documentation for a horrendously overblown object model, somewhat reminiscent of Microsoft's corporate structure in that it contained many layers that did nothing but manage other things, and very few layers that did anything useful, but from which I was able to determine that the Application.Current property seems not to have a RootVisual property.

    Back to Google, and it turns out that there is such a property, at least in theory. It's only supported on Silverlight 3.0 and 4.0 and Windows Phone 7.0 and you don't mention which of the dozen or so platforms Microsoft's many management teams have now managed to get out there competing with each other you're trying to deal with, so I thought I'd give up.

    BTW, your thread title is all wrong: it should be "Everything Microsoft has done in years many steps backwards in every way; the mere fact that they can't construct a web site that provides access to the documentation of their products unless one turns to the company they regard as their greatest competitor to find what one needs says it all" but I suppose that wouldn't fit.

    I don't think anybody else has managed to create such an impenetrable thicket of their documentation as MS have with the MSDN Library these days. That fact alone should give you a strong hint that you should consider turning your attention to other technologies. Microsoft may continue to be an apparently viable option for a few more years, but only in the way that people could still say IBM were a viable option around 1987. The writing was already on the wall for IBM then, and it's there for MS now.
    Last edited by NickFitz; 20 December 2010, 06:45.

    Comment


      #3
      Originally posted by NickFitz View Post
      Out of idle curiosity I went to have a look through the WPF documentation at MSDN Library but it was impossible to find.

      A Google search uncovered it at the URL Windows Presentation Foundation - I really should have guessed that it would come under the name 754130, I suppose.

      On the offchance that I might still be able to help, I scanned the available resources and had a look at "Layout System" (as mere n00bs like myself call it - a MSMaven would of course know that its real name is 745058). This eventually led me to some documentation for a horrendously overblown object model, somewhat reminiscent of Microsoft's corporate structure in that it contained many layers that did nothing but manage other things, and very few layers that did anything useful, but from which I was able to determine that the Application.Current property seems not to have a RootVisual property.

      Back to Google, and it turns out that there is such a property, at least in theory. It's only supported on Silverlight 3.0 and 4.0 and Windows Phone 7.0 and you don't mention which of the dozen or so platforms Microsoft's many management teams have now managed to get out there competing with each other you're trying to deal with, so I thought I'd give up.

      BTW, your thread title is all wrong: it should be "Everything Microsoft has done in years many steps backwards in every way; the mere fact that they can't construct a web site that provides access to the documentation of their products unless one turns to the company they regard as their greatest competitor to find what one needs says it all" but I suppose that wouldn't fit.

      I don't think anybody else has managed to create such an impenetrable thicket of their documentation as MS have with the MSDN Library these days. That fact alone should give you a strong hint that you should consider turning your attention to other technologies. Microsoft may continue to be an apparently viable option for a few more years, but only in the way that people could still say IBM were a viable option around 1987. The writing was already on the wall for IBM then, and it's there for MS now.
      For once I somewhat agree. MS technologies have all gone mad over the last few years.

      Comment


        #4
        I think Bill Gates must have spilled Nick's pint at some point. MSDN has generally been getting worse, but it's still better than trying to piece together information on HTML, as I've been finding out (and even that's better than Adobe's Flash documentation).

        I don't know about WPF, but it sounds like they've implemented a proper graphics system, where you wouldn't have such crude concepts of a rectangle with top,left properties. What you have is an object with a size and a transform. I would expect there's a way of finding the width and height of the object, so the top left is -width/2, -height/2, and then apply the transform to that.
        Will work inside IR35. Or for food.

        Comment


          #5
          I thought WinForms had poor performance but they really outdid themselves with WPF...

          Comment


            #6
            Originally posted by VectraMan View Post
            I think Bill Gates must have spilled Nick's pint at some point. MSDN has generally been getting worse, but it's still better than trying to piece together information on HTML, as I've been finding out (and even that's better than Adobe's Flash documentation).

            I don't know about WPF, but it sounds like they've implemented a proper graphics system, where you wouldn't have such crude concepts of a rectangle with top,left properties. What you have is an object with a size and a transform. I would expect there's a way of finding the width and height of the object, so the top left is -width/2, -height/2, and then apply the transform to that.
            Lost you there buddy, if I know how wide something is, and how high something is doesn't mean I know where it is, even if I divide by 2 and subtract one from t'other.
            Knock first as I might be balancing my chakras.

            Comment


              #7
              Originally posted by suityou01 View Post
              Lost you there buddy, if I know how wide something is, and how high something is doesn't mean I know where it is, even if I divide by 2 and subtract one from t'other.
              The transform tells you where it is. The object will have its own co-ordinate space, probably with 0,0 at its centre, and the transform will convert from object co-ordinates to screen co-ordinates so it can be displayed (TransformToVisual sounds like it would do that). So assuming 0,0 is at the centre, if you transform -width/2,-height/2 then you have the position of the top left where it ends up on the screen.

              Of course if it's been rotated 180 degrees, that'll now be the bottom right...
              Will work inside IR35. Or for food.

              Comment


                #8
                MSDN has always been horrible IMO. But the technologies themselves, not. I use books or internet forums when I'm stuck just as with Spring or other Java stuff.

                Maybe Nick's getting a bit old for all these new things
                Originally posted by MaryPoppins
                I'd still not breastfeed a nazi
                Originally posted by vetran
                Urine is quite nourishing

                Comment


                  #9
                  If I remember correctly (though I haven't touched on it for a long time!), a FrameworkElement has a Margin property which will give you the X/Y of an object on it's container (eg: a Canvas).

                  However, not sure if it applies to a UIElement.

                  Comment

                  Working...
                  X