Xamarin Forms (버전 2.5.0.121934)를 사용하여 Android, iOS 및 UWP를 타겟팅하는 앱에서 작업하고 있습니다. 사용자 정의 렌더러가 필요한 일부 텍스트에 밑줄과 취소 선을 추가해야합니다. Android 및 iOS의 경우 모든 것이 정상적으로 작동하며 UWP에서는 에 취소 선 또는 밑줄을 올바르게 적용했지만 해당 장식을 제거하지 않아도 작동하지 않습니다.Xamarin Forms UWP 앱에서 TextDecoration을 지울 수 없습니다.
[assembly: ExportRenderer(typeof(EnhancedLabel), typeof(EnhancedLabelRenderer))]
namespace myApp.UWP
{
public class EnhancedLabelRenderer : LabelRenderer
{
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
var strikethrough = ((EnhancedLabel)sender).Strikethrough;
var underline = ((EnhancedLabel)sender).Underline;
if (strikethrough && underline)
{
Control.TextDecorations = TextDecorations.Strikethrough | TextDecorations.Underline;
}
else if (strikethrough)
{
Control.TextDecorations = TextDecorations.Strikethrough;
}
else if (underline)
{
Control.TextDecorations = TextDecorations.Underline;
}
else
{
Control.TextDecorations = TextDecorations.None;
}
}
}
}
EnhancedLabel
가 Xamarin.Forms.Label
을 연장 취소 또는 밑줄 지정 간단한 BindableProperty
필드를 추가하는 간단한 클래스이다
여기에 UWP 렌더러의 전체이다.
렌더러가 올바르게 TextDecorations.None
으로 설정되어 있지만 UI에 영향을 미치지 않습니다. 디버거에서이 작업을 수행했으며 실제로 ExtendedLabel
내의 TextBlock
의 상태는 TextDecorations.None
이지만 UI는 여전히 밑줄을 긋거나 취소 선으로 그립니다. (본질적으로 그 중 하나를 추가 할 수는 있지만 둘 다 할 수 없습니다. 제거하십시오).
저는 Xamarin 문서를 읽고 Bugzilla의 버그를 살펴본 결과 아무런 단서도 발견하지 못했습니다. 다른 사람이이 문제를 겪었습니까? UWP 관련 전화가 있는지 궁금해서 제가 놓친 것을 만들거나 TextDecorations
을 사용하여 스타일을 적용하는 잘못된 방법이거나 실제로 버그를 발견 한 것입니다.
친구가 다음과 같이 지적했습니다. https://stackoverflow.com/questions/16480344/programatically-removing-strikethrough-textdecoration-from-code-behind-in-wpf; WPF에서 작동했던 것은 UWP에는 적용되지 않습니다. – Ickster