2017-04-05 58 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属性。