C#-证明标签Xamarin形式的文本
作者:互联网
我试图证明标签Xamarin表单中的文本合理,但无法解决,如何不使用webview像文本一样对文本进行正则化(而非仅对样式进行正则化)
我已经附上了我的代码,但只保留了理由
string strText="MY LONG TEXT IS GOING HERE";
var lblMSG = new Label {TextColor = Color.Black };
lblMSG.Text=strText;
lblMSG.LineBreakMode = LineBreakMode.WordWrap;
lblMSG.HorizontalOptions = LayoutOptions.Fill;
lblMSG.HorizontalTextAlignment = TextAlignment.Start;
lblMSG.VerticalTextAlignment = TextAlignment.Center;
StackLayout stk= new StackLayout { Children = { lblMSG}, BackgroundColor = Color.White ,HorizontalOptions =LayoutOptions.FillAndExpand }
解决方法:
而不是使用标签.我使用了HtmlWebViewSource.
下面是一个示例:
XAML:
<StackLayout x:Name="webViewLayout"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<!-- view codebehind for WebView for overview text -->
</StackLayout>
XAML的代码背后(在您的情况下,viewModel.Model.Content = strText):
var browser = new WebView();
browser.HorizontalOptions = LayoutOptions.FillAndExpand;
browser.VerticalOptions = LayoutOptions.FillAndExpand;
var source = new HtmlWebViewSource();
var text = "<html>" +
"<body style=\"text-align: justify;\">" +
String.Format("<p>{0}</p>", viewModel.Model.Content) +
"</body>" +
"</html>";
source.Html = text ;
browser.Source = source;
webViewLayout.Children.Add(browser);
标签:xamarin,xamarin-forms,c 来源: https://codeday.me/bug/20191118/2026916.html