2016-08-19 38 views
1

我試圖標籤Xamarin窗體對齊文本但想不出,
如何將文本證明(未定型證明專用)同樣喜歡的圖片,而無需使用的WebView

enter image description here
我重視我的代碼,但其使用標籤左對齊只證明在標籤文本xamarin形成

 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 } 
+0

你的意思的造型文本?如果是的話,你需要手動完成。 –

+0

沒有造型只證明 - 對於造型我使用FormattedString() –

+0

「lblMSG.Horizo​​ntalTextAlignment = TextAlignment.Start;」使文本從左側開始。嘗試將其更改爲TextAlignment.Center。 –

回答

3

代替。我使用了一個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); 
+2

簡單但有效。非常感謝你。 –

+0

在給定的解決方案中,我可以更改字體嗎?我需要「蒙特塞拉特」字體到我的元素而無需連接到互聯網,請給我任何解決方案或任何想法? – nikhil

+0

您需要將字體文件添加到您的項目中,然後才能引用它。 – nishantvodoo