在有一个项目中,我在屏幕上有三个 Entry 控件。它们都绑定到所有包含文本的支持属性。当我运行应用程序时,只有具有焦点的入口控件才会显示其文本。其他输入控件在获得焦点之前不会显示其文本。我已将问题报告给 Microsoft。我只是好奇是否有其他人遇到过这个问题并找到了解决方法,直到它被修复。(我作为 UWP 项目运行)
复制的步骤。创建一个名为 EntryControlError 的新 Xamarin 表单应用程序。请在解决方案中包含一个 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));
}
}
}
运行应用程序,屏幕将如下所示:
如果您在不输入任何内容的情况下单击第二个或第三个条目控件,它们的绑定文本将自动出现。