This is a migrated thread and some comments may be shown as answers.

WPF: Get Canvas.Left and Top Attached Properties

6 Answers 429 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Lorenz
Top achievements
Rank 1
Lorenz asked on 08 Dec 2014, 01:35 PM
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

6 Answers, 1 is accepted

Sort by
0
Lorenz
Top achievements
Rank 1
answered on 08 Dec 2014, 03:20 PM
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
0
Boyan Boev
Telerik team
answered on 11 Dec 2014, 09:44 AM
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
 
0
Lorenz
Top achievements
Rank 1
answered on 18 Dec 2014, 04:00 PM
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
0
Accepted
Boyan Boev
Telerik team
answered on 23 Dec 2014, 02:10 PM
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
 
0
Lorenz
Top achievements
Rank 1
answered on 05 Jan 2015, 02:03 PM
Hi Boyan,

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

Kind regards,
Benoît
0
Boyan Boev
Telerik team
answered on 06 Jan 2015, 08:07 AM
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
 
Tags
General Discussions
Asked by
Lorenz
Top achievements
Rank 1
Answers by
Lorenz
Top achievements
Rank 1
Boyan Boev
Telerik team
Share this question
or