0
    <?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:d="http://xamarin.com/schemas/2014/forms/design"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                 mc:Ignorable="d"

                <StackLayout
           x:Name="StackLayout" >
            <!-- Place new controls here -->
            <Label
                x:Name="label"
                Text=" "
                HorizontalOptions="FillAndExpand"
                VerticalOptions="StartAndExpand"
              />
               <Entry
                x:Name="entry1"
               Placeholder=" X "
                Keyboard="Numeric"
                TextChanged="Entry1_TextChanged"
                />
  </StackLayout>

</ContentPage>

Как можно сделать так,что бы при изменении текста в entry текст копировался в label? В примере в книге элементы располагаются в ContentPage и к ним можно обращаться по x:Name,что в моем случае не работает. Найти пример со StackLayout сам не смог,так же как и информации касательно обращения к элементам внутри StackLayout

1 ответ 1

1

Можете установить привязку к entry по имени и система автоматически будет изменять значение

Text="{Binding Text, Source={x:Reference entry1}}"

Вместо entry1 можете поставить id другого компонента

<Label x:Name="label" 
   Text="{Binding Text, Source={x:Reference entry1}}" 
   HorizontalOptions="FillAndExpand"        
   VerticalOptions="StartAndExpand" />
<Entry x:Name="entry1" 
   Placeholder=" X "
   Keyboard="Numeric"   
   TextChanged="Entry1_TextChanged" />

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.