本文介绍了对齐标签xamarin形式的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在标签Xamarin表单中对齐文本,但无法,
如何在不使用webview的情况下像图片一样对文本进行对齐(不是仅对样式进行对齐)
我已经附上了我的代码,但仅能证明其合理性
Am trying to justify text in Label Xamarin Forms but couldnt ,
how to justify the text (not styling justify only) same like a picture without using webview
I have attached my code but its justify left only
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.
Instead of using a label. I used a HtmlWebViewSource.
下面是一个示例:
XAML:
<StackLayout x:Name="webViewLayout"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<!-- view codebehind for WebView for overview text -->
</StackLayout>
XAML的代码背后(在您的情况下,viewModel.Model.Content = strText):
Code Behind of XAML (viewModel.Model.Content = strText in your case):
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形式的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!