Xamarin 转换原始值

问题描述

我试图在 Xamarin.MacOS 中为 NSButton 的标题加下划线。 在可变属性字符串中,我使用

DF <- structure(list(x = c(" Accession of China"," Afghanistan"," Albania"," Algeria"," Andean Community"," Andorra"),y = c(0.401,0.486,0.581,0.431,0.341,0.378)),class = "data.frame",row.names = c(NA,-6L))

它不起作用。 Swift 中的建议是使用

attrString.AddAttribute(NsstringAttributeKey.Underlinestyle,NSNumber.FromInt32((int)NSUnderlinestyle.Single),range);

在 Xamarin.MacOS 中,没有 NSUnderlinestyle.Single.RawValue。如何获得 NSUnderlinestyle 枚举的 RawValue?谢谢。

解决方法

首先,快速回顾一下。 NSUnderlineStyle 是具有以下值的枚举:

NSUnderlineStyleNone = 0x00,NSUnderlineStyleSingle = 0x01,NSUnderlineStyleThick = 0x02,NSUnderlineStyleDouble = 0x09,NSUnderlinePatternSolid = 0x0000,NSUnderlinePatternDot = 0x0100,NSUnderlinePatternDash = 0x0200,NSUnderlinePatternDashDot = 0x0300,NSUnderlinePatternDashDotDot = 0x0400,NSUnderlineByWord = 0x8000 

所以我们可以检查下面的代码

string prefixedHex = "0x01";
            
int intValue = Convert.ToInt32(prefixedHex,16);

NSMutableAttributedString str = new NSMutableAttributedString();
      str.AddAttribute(NSStringAttributeKey.UnderlineStyle,NSNumber.FromInt32(1),range);

button.AttributedTitle = str;
,

我是这样添加下划线的:

str.AddAttribute(NSStringAttributeKey.UnderlineStyle,new NSNumber((int)NSUnderlineStyle.Single),new NSRange(0,str.Length));

我可以确认这在 NSTextViewNSButton 中都有效

,

原始代码没有任何问题。

attrString.AddAttribute(NSStringAttributeKey.UnderlineStyle,NSNumber.FromInt32((int)NSUnderlineStyle.Single),range);

我忘记在 OnElementPropertyChanged 函数中设置此属性。 感谢您确认它有效,这促使我重新调查我的代码。我花了几天调试它,认为问题出在 rawValue 上。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...