WPF: Get Canvas.Left and Top Attached Properties

7 posts, 1 answers
  1. Benoit
    Benoit avatar
    17 posts
    Member since:
    Oct 2014

    Posted 08 Dec 2014 Link to this post

    Hi,

    I have a requirement where I have to test the position of different Elements.
    This position is set in our application using a Parent Cancas as container. Then our custom user controls are placed using Cancas attached properties: "Top" and "Left".

    In our test scenario we tried to retrieve this value withe the following code:

    var left = userControl.GetAttachedProperty<double>("Canvas", "Left");<br>var top = userControl.GetAttachedProperty<double>("Canvas", "Top");

    But this code throw an exception:
    [WPF Extension Error] Details: ArtOfTest.WebAii.Silverlight.NoSuchPropertyException: Unable to find attached property owner class 'Canvas'
       bei Telerik.TestingFramework.XamlExtension.ClientServices.GetAttachedPropertyValue(AutomationProperty property, Object obj)
       bei Telerik.TestingFramework.XamlExtension.ClientServices.GetRealProperty(AutomationReference reference, AutomationProperty property)
       bei Telerik.TestingFramework.XamlExtension.ClientProcessor.ProcessCommand(String command)

    Do I do something wrong? Is there a way to test the position of UI elements ?

    Thanks.
    Benoît
  2. Benoit
    Benoit avatar
    17 posts
    Member since:
    Oct 2014

    Posted 08 Dec 2014 Link to this post

    I think it's possible to use the GetRectangle method by passing the relativeTo element (here it will be my canvas container).

    This is not optimal in my case but I could be a workaround. If anybody knows a way to retrieve the Canvas.Left and Canvas.Top properties, please let know.

    Thanks.
    Benoît
  3. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 11 Dec 2014 Link to this post

    Hi Benoit,

    Your code looks correct. Could you please give us some demo or access to your application so we can try to reproduce the issue and give you a solution.

    Also please double check that the property is of type double.

    Hope to hear from you soon.

    Regards,
    Boyan Boev
    Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  4. Benoit
    Benoit avatar
    17 posts
    Member since:
    Oct 2014

    Posted 18 Dec 2014 in reply to Boyan Boev Link to this post

    Hi Boyan,

    Please find attached a VS solution containing a small WPF application, and some UI Automation tests (in UiAutomationTest.cs):
    • When_RetrieveCanvasAttachedProperties
    Thanks,
    Benoît
  5. Answer
    Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 23 Dec 2014 Link to this post

    Hi Benoit,

    Thank you again for the sample.

    You should use this syntax for the canvas:

    var left = textblock.GetAttachedProperty<double>("System.Windows.Controls.Canvas", "Left");

    Let me know if this helps.

    Regards,
    Boyan Boev
    Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  6. Benoit
    Benoit avatar
    17 posts
    Member since:
    Oct 2014

    Posted 05 Jan 2015 in reply to Boyan Boev Link to this post

    Hi Boyan,

    Sorry for my late feedback.
    Good news, it works with your syntax!

    Kind regards,
    Benoît
  7. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 06 Jan 2015 Link to this post

    Hello Benoit, 

    Glad to hear that.

    If you need further help please let us know.

    Regards,
    Boyan Boev
    Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
Back to Top