У меня есть проект, в котором у меня есть три элемента управления Entry на экране. Все они связаны с базовыми свойствами, в которых есть текст. Когда я запускаю приложение, только элемент управления вводом, который имеет фокус, покажет его текст. Другие элементы управления вводом не будут отображать свой текст, пока они не получат фокус. Я сообщил о проблеме в Microsoft. Мне было просто любопытно, сталкивался ли кто-нибудь еще с проблемой и нашел обходной путь, пока она не будет устранена. (Я работаю как проект UWP)
Шаги для репликации. Создайте новое приложение форм Xamarin с именем EntryControlError. Пожалуйста, включите в решение проект UWP.
После создания проекта откройте файл MainPage.xaml и замените все содержимое на XAML ниже:
<?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"
BackgroundColor="#D0E1F9"
x:Class="EntryControlError.MainPage">
<ContentPage.Content>
<StackLayout x:Name="slFullPage" Orientation="Vertical" HorizontalOptions="Fill" VerticalOptions="FillAndExpand" Margin="0,32,0,0" Padding="0,0,0,0">
<ScrollView HorizontalOptions="Fill" VerticalOptions="FillAndExpand">
<StackLayout Orientation="Vertical" HorizontalOptions="Fill" VerticalOptions="FillAndExpand">
<StackLayout x:Name="slTextHeader" Orientation="Vertical" HorizontalOptions="Center" VerticalOptions="Start">
<Label x:Name="lblTextHeaderInfo" Text="Enter Text - Max Three Lines" HorizontalOptions="Center" VerticalOptions="Start"
TextColor="#283655" FontAttributes="Bold" FontSize="Small" />
<Entry x:Name="txtHeaderText1" HorizontalOptions="Fill" VerticalOptions="Start" Text="{Binding KioskHeaderText1, Mode=TwoWay}"
TextColor="#283655" HorizontalTextAlignment="Center" FontAttributes="Bold" FontSize="Medium" />
<Entry x:Name="txtHeaderText2" HorizontalOptions="Fill" VerticalOptions="Start" Text="{Binding KioskHeaderText2, Mode=TwoWay}"
TextColor="#283655" HorizontalTextAlignment="Center" Margin="0,-8,0,0" FontAttributes="Bold" FontSize="Medium" />
<Entry x:Name="txtHeaderText3" HorizontalOptions="Fill" VerticalOptions="Start" Text="{Binding KioskHeaderText3, Mode=TwoWay}"
TextColor="#283655" HorizontalTextAlignment="Center" Margin="0,-8,0,0" FontAttributes="Bold" FontSize="Medium" />
</StackLayout>
</StackLayout>
</ScrollView>
</StackLayout>
</ContentPage.Content>
</ContentPage>
Замените все в Файл MainPage.xaml.cs со следующим:
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using Xamarin.Forms;
namespace EntryControlError
{
// Learn more about making custom code visible in the Xamarin.Forms previewer
// by visiting https://aka.ms/xamarinforms-previewer
[DesignTimeVisible(false)]
public partial class MainPage : ContentPage, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string _KioskHeaderText1;
public string KioskHeaderText1
{
get { return _KioskHeaderText1; }
set
{
_KioskHeaderText1 = value;
OnPropertyChanged();
}
}
private string _KioskHeaderText2;
public string KioskHeaderText2
{
get { return _KioskHeaderText2; }
set
{
_KioskHeaderText2 = value;
OnPropertyChanged();
}
}
private string _KioskHeaderText3;
public string KioskHeaderText3
{
get { return _KioskHeaderText3; }
set
{
_KioskHeaderText3 = value;
OnPropertyChanged();
}
}
public MainPage()
{
try
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
NavigationPage.SetHasBackButton(this, false);
KioskHeaderText1 = "Line 1 Text";
KioskHeaderText2 = "Line 2 Text";
KioskHeaderText3 = "Line 3 Text";
txtHeaderText1.BindingContext = this;
txtHeaderText2.BindingContext = this;
txtHeaderText3.BindingContext = this;
}
catch (Exception ex)
{
Debug.WriteLine("Error: " + ex.Message);
}
}
/// <summary>
/// Manual Notification to subscribers that a property has changed.
/// </summary>
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
Запустите приложение, и экран будет выглядеть так:
![enter image description here](https://i.stack.imgur.com/zNoyr.png)
Если вы щелкнете по второму или третьему элементу управления вводом, ничего не введя, автоматически появится связанный текст.