从Xamarin.Forms中的代码将Label的文本绑定到字符串

时间:2018-07-20 22:33:47

标签: xaml text xamarin.forms binding label

我正在尝试做这样的事情:

totalPoints.Text = "50 points";

其中totalPoints是XAML中x:Name的{​​{1}}。

不幸的是,文件后面的代码无法识别totalPoints。

这是UWP绑定中的常用方法。

这在Xamarin.Forms中如何工作?

这是我的Xaml:

Label

这是背后的代码:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:local="clr-namespace:MySolutionName"
         x:Class="MySolutionName.MainPage"
         xmlns:control="clr-namespace:ProgressRingControl.Forms.Plugin;assembly=ProgressRing.Forms.Plugin">
<ContentPage.Content>

    <Grid>

        <Grid.RowDefinitions>
            <RowDefinition Height="70"/>
            <RowDefinition Height="50"/>
            <RowDefinition Height="50"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="70"/>
        </Grid.RowDefinitions>
        <Image Grid.Row="0" Grid.RowSpan="5"
            Aspect="AspectFill"
        Source="backgroundfull.jpeg"/>


        <BoxView Grid.Row="0" WidthRequest="100" Color="Black" Opacity="0.5"/>
        <Grid Grid.Row="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>

        </Grid>
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Label x:Name="testingLabel" Grid.Column="0"/>


        </Grid>
        <Grid Grid.Row="2" ColumnSpacing="0" RowSpacing="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

        </Grid>
        <ScrollView Grid.Row="3">
            <StackLayout>

            </StackLayout>
        </ScrollView>

        </Grid>
    </Grid>

</ContentPage.Content>

我注意到一件事。 15分钟后,智能提示错误消失,x:Name标签被识别。 它与内存不足之类的东西有关吗?

0 个答案:

没有答案