2017-04-05 57 views
1

我正在製作一個應用程序,其中多次有與按鈕組合的文本標籤或部分文本具有不同顏色的應用程序。文本與Xamarin表單中的鏈接按鈕對齊

這個時候,我需要做到這一點: enter image description here

「登錄」按鈕,文本必須有一個動作重視它,也有從文本的其餘部分不同的外觀。

我已經嘗試使用水平屬性的StackView,但它僅僅依賴於設備和文本長度的寬度,並且它不在屏幕上水平居中。

的HTML我會做類似

Already have an account? <a>Sign in</a> 

是否有類似的東西在XAML?

回答

1

具有自動大小列的網格和Sign In標籤上的TapGestureRecognizer是一種可以在iOS和Android上產生一致外觀的方法,因爲不使用按鈕。

<Grid Padding="20"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="40" /> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="Auto" /> 
     <ColumnDefinition Width="Auto" /> 
    </Grid.ColumnDefinitions> 
    <Label Grid.Row="0" Grid.Column="0" Text="Already have an account?" TextColor="Black" BackgroundColor="White" /> 
    <Label x:Name="onSignIn" Grid.Row="0" Grid.Column="1" Text="Sign In" TextColor="Red" BackgroundColor="White" /> 
</Grid> 

enter image description here

在後面的代碼:

var tapGestureRecognizer = new TapGestureRecognizer(); 
tapGestureRecognizer.Tapped += (sender, e) => D.WriteLine("Tapped"); 
onSignIn.GestureRecognizers.Add(tapGestureRecognizer); 
1

是 - 跨度。您可以使用具有不同的字體跨度,顏色,大小等

<Label> 
    <Label.FormattedText> 
     <FormattedString> 
      <FormattedString.Spans> 
       <Span Text="Hello" ForegroundColor="Red" FontAttributes="Italic" FontSize="10" /> 
       <Span Text="World" ForegroundColor="Blue" FontSize="10" /> 
      </FormattedString.Spans> 
     </FormattedString> 
    </Label.FormattedText> 
</Label> 

跨度文本不是綁定建立一個格式化字符串,但FormattedText的標籤是,這樣你就可以在你的視圖模型,並結合建立FormattedString那到FormattedText屬性。