Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xaml 文本与Xamarin表单中的链接按钮对齐_Xaml_Xamarin_Xamarin.forms - Fatal编程技术网

Xaml 文本与Xamarin表单中的链接按钮对齐

Xaml 文本与Xamarin表单中的链接按钮对齐,xaml,xamarin,xamarin.forms,Xaml,Xamarin,Xamarin.forms,我正在开发一个应用程序,其中多次有文本标签与按钮组合,或者部分文本具有不同的颜色 这一次,我需要实现以下目标: “登录”文本按钮必须有一个附加的操作,并且具有与其他文本不同的外观 我尝试过使用带有水平属性的StackView,但它太依赖于设备的宽度和文本长度,并且在屏幕上看起来没有水平居中 在Html上,我会做如下事情 Already have an account? <a>Sign in</a> 已经有账户了吗?登录 XAML上有类似的东西吗?是-是。您可以使用具

我正在开发一个应用程序,其中多次有文本标签与按钮组合,或者部分文本具有不同的颜色

这一次,我需要实现以下目标:

“登录”文本按钮必须有一个附加的操作,并且具有与其他文本不同的外观

我尝试过使用带有水平属性的StackView,但它太依赖于设备的宽度和文本长度,并且在屏幕上看起来没有水平居中

在Html上,我会做如下事情

Already have an account? <a>Sign in</a>
已经有账户了吗?登录

XAML上有类似的东西吗?

是-是。您可以使用具有不同字体、颜色、大小等的跨距构建格式化字符串

<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属性。

带有自动大小列的网格和
登录标签上的
TapGestureRecognitor
是一种在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>

您也可以尝试此现有解决方案:

3.1.0中提供了可绑定跨距,3.2.0中为跨距添加了手势。享受吧!
var tapGestureRecognizer = new TapGestureRecognizer();
tapGestureRecognizer.Tapped += (sender, e) => D.WriteLine("Tapped");
onSignIn.GestureRecognizers.Add(tapGestureRecognizer);