xamarin - Xamarin 转换 rawValue
问题描述
我试图在 Xamarin.MacOS 中强调 NSButton 的标题。在可变属性字符串中,我使用
attrString.AddAttribute(NSStringAttributeKey.UnderlineStyle, NSNumber.FromInt32((int)NSUnderlineStyle.Single), range);
它不起作用。Swift 中的建议是使用
let underlineAttribute = [NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single.rawValue]
在 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;
推荐阅读
- ubuntu - Apache2 总是将默认站点加载为我的 PrestaShop 首页
- javascript - Typescript - 如何推断非调用函数中的泛型?
- r - 如何将格式化的表格输出保存为 .png?
- javascript - 如何检查值是否已包含在数组javascript中
- reactjs - Redux 设计问题:可以/应该将经常更改的状态(光标索引)保留在存储之外吗?如果是这样,替代方案?
- python - 我是 python 新手,第一个 if 语句出现错误
- html - Z-index 不适用于伪元素 ::after
- arrays - Powershell将范围作为数组传递?
- c# - 在服务错误 C# 上回滚 MVC 中的更改
- r - R:如何使用函数生成部分函数参数