C# 如何从代码隐藏中调用viewcell内的标签

C# 如何从代码隐藏中调用viewcell内的标签,c#,visual-studio,xaml,xamarin,xamarin.forms,C#,Visual Studio,Xaml,Xamarin,Xamarin.forms,这是我的listview,基本上我希望屏幕上显示的文本是一个变量。因此,通常您只需将x:Name=“Pair”放在标签中,然后在标签后面写var Pair=Pair.Text但在这种情况下,这不起作用。我的预期结果是屏幕上以变量形式显示的文本 <ListView x:Name="myPriceList" IsPullToRefreshEnabled="False" > <ListView.ItemTemplate>

这是我的listview,基本上我希望屏幕上显示的文本是一个变量。因此,通常您只需将x:Name=“Pair”放在标签中,然后在标签后面写var Pair=Pair.Text但在这种情况下,这不起作用。我的预期结果是屏幕上以变量形式显示的文本

<ListView x:Name="myPriceList" IsPullToRefreshEnabled="False" >
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <Label Text="{Binding Pair}" FontAttributes="Bold" TextColor="Black" FontSize="15" Margin="0,0,0,-5"/>
                <Label Text="{Binding buyPrice}" TextColor="DarkSlateGray" FontSize="13" HorizontalTextAlignment="Start"/>
                <Label Text="{Binding buyAmount}" FontAttributes="Bold" TextColor="Black" FontSize="17" Margin="0,0,0,-5" HorizontalTextAlignment="End"/>
                <Label Text="{Binding worth}" TextColor="DarkSlateGray" FontSize="13" HorizontalTextAlignment="End"/>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>


标签中显示的文本是来自模型的数据绑定,因此您可以从模型中获取它们的值。您不能按名称访问模板中的项目。@谢谢!