How to get text color from text in WPF cell?

Class library usage, coding and language questions.
winniethedragon
Posts: 6
Joined: Wed May 27, 2015 9:22 am

How to get text color from text in WPF cell?

Post by winniethedragon » Wed May 27, 2015 9:39 am

Hello,

I am trying to get the text color in the table...but this code doesn't seem to work... Please help!

I want to tell the difference between row 182 and 183...

foreach (Ranorex.Row row in PepRows)
{
Ranorex.Cell cell = row.Cells.ElementAt(3);
Ranorex.Text cellText = cell.Text.ToString();
var color = cellText.Element.GetAttributeValue("ForeColor");
}
Attachments
TextColor.png
TextColor.png (38.2 KiB) Viewed 2181 times

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: How to get text color from text in WPF cell?

Post by krstcs » Wed May 27, 2015 2:27 pm

Code: Select all

foreach (Ranorex.Row row in PepRows)
{
Ranorex.Cell cell = row.Cells.ElementAt(3);
//Ranorex.Text cellText = cell.Text.ToString();   <-- This is getting a STRING object, not a Ranorex.Text object, which is what you are telling .NET you want.
Ranorex.Text cellText = cell.Text;  //Try this.
var color = cellText.Element.GetAttributeValue("ForeColor");
}
Shortcuts usually aren't...

winniethedragon
Posts: 6
Joined: Wed May 27, 2015 9:22 am

Re: How to get text color from text in WPF cell?

Post by winniethedragon » Wed May 27, 2015 9:06 pm

It's strange, I did the following....

public string PeptideTableReadOnlyStatus()
{
string ToPrint = "***";
Ranorex.Table PepTable = repo.PeakView.PMControl.PeptidesTable;
for (int i = 1; i < PepTable.Rows.Count; i++)
{
Ranorex.Row PepRow = PepTable.Rows.ElementAt(i);
Ranorex.Cell PepCell = PepRow.Cells.ElementAt(4);
Ranorex.Text PepCellText = PepCell.Text; -->This gives an error "System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Ranorex.RxPathException: Invalid RxPath 'EC[CAM]NLAEVPTHAVVVRPEK'. ---> Ranorex.RxPathException: Invalid character at character position 7."
//var color = PepCellText.Element.GetAttributeValue("ForeColor");
//ToPrint = ToPrint + PepCell.Text; //-->But if I don't assign PepCell.Text to a <Ranorex.Text>, and just simply print it out to the screen, this works!

}

winniethedragon
Posts: 6
Joined: Wed May 27, 2015 9:22 am

Re: How to get text color from text in WPF cell?

Post by winniethedragon » Wed May 27, 2015 9:35 pm

Okay, I finally got the Ranorex.Text working by doing this:

Ranorex.Text PepCellText = PepCell.FindSingle<Ranorex.Text>(".//text");

But then the ColorAttribute is giving me an error:
var color = PepCellText.Element.GetAttributeValue("ForeColor");
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to get text color from text in WPF cell?

Post by Support Team » Mon Jun 01, 2015 2:14 pm

hi winniethedragon,

It seems that you have misspelled the attributename in the GetAttributeValue Method.
Please use the following line of code to get the Foregroundcolor
var color = PepCellText.Element.GetAttributeValue("ForegroundColor");
Regards,
Markus (S)
.
Image

winniethedragon
Posts: 6
Joined: Wed May 27, 2015 9:22 am

Re: How to get text color from text in WPF cell?

Post by winniethedragon » Mon Jun 01, 2015 7:47 pm

Hello Markus,

Thank you for your reply!

However, I am getting this error now using the "ForegrounColor" attribute...
==>var color = PepCellText.Element.GetAttributeValue("ForegroundColor");
System.NullReferenceException: Object reference not set to an instance of an object.

This is the exact same problem when I used the code in my other post "BackColor Attribute", which you also replied to as well.

Here is the snapfile you requested. Thank you for all your help!

Winnie

BTW: How do I get a list of all the available attributes?
Attachments
PeptideTableSnapShot.rxsnp
The table I am interested in is under MainForm->Element MdiClient->Form 1->Element 'SwathData'->Table 'Fragment Table'
(278.76 KiB) Downloaded 83 times

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to get text color from text in WPF cell?

Post by Support Team » Wed Jun 03, 2015 2:10 pm

Hi winniethedragon,

Thank you for the snapshot. As I can see in the snapshot, you are using Ranorex 5.2.2. The WPF color attribute was introduced in Ranorex 5.3.1.

Therefore, I'd suggest updating to the latest version (5.3.2).
Please let me know if you are able to get the Color attribute with Ranorex 5.3.2.

Regards,
Markus (S)
.
Image

winniethedragon
Posts: 6
Joined: Wed May 27, 2015 9:22 am

Re: How to get text color from text in WPF cell?

Post by winniethedragon » Thu Jun 04, 2015 6:20 pm

It looks like my license does not let me use Ranorex 5.3.2...
Any other way I can get access to the color attribute? Thanks!

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to get text color from text in WPF cell?

Post by Support Team » Fri Jun 05, 2015 1:38 pm

Hi winniethedragon,

Unfortunately, there is no other way to get the color with the previous versions of Ranorex because this version still uses the legacy WPF plug-in which does not support this attribute.

Regards,
Bernhard
.
Image