xamarin.forms - Xamarin.Forms 条目文本已添加但未显示
问题描述
我在启动应用程序时制作了一个 Pin Validator。这是我的代码:
<ContentPage.Content>
<StackLayout Spacing="10" VerticalOptions="Center" Margin="10,0,10,0" >
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="1.3*" />
<RowDefinition Height="*" />
<RowDefinition Height="0.5*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowSpacing>
<OnPlatform x:TypeArguments="x:Double" Android="20" iOS="20" />
</Grid.RowSpacing>
<Grid.ColumnSpacing>
<OnPlatform x:TypeArguments="x:Double" Android="20" iOS="20" />
</Grid.ColumnSpacing>
<Frame BorderColor="#006BE6" BackgroundColor="WhiteSmoke" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" >
<Entry TextColor="#006BE6" FontSize="48" IsPassword="True" x:Name="Output" Text="{Binding Pin}" HorizontalOptions="Center" VerticalOptions="Center" IsReadOnly="True">
<Entry.Behaviors>
<behaviors:EntryLengthValidatorBehavior MaxLength="4" />
</Entry.Behaviors>
</Entry>
</Frame>
<Button TextColor="#006BE6" Text="1" Grid.Row="3" Grid.Column="1" Command="{Binding LoadNumberCommand}" CommandParameter="1" BorderColor="#006BE6" BorderWidth="1" BackgroundColor="WhiteSmoke" />
<Button TextColor="#006BE6" Text="2" Grid.Row="3" Grid.Column="2" Command="{Binding LoadNumberCommand}" CommandParameter="2" BorderColor="#006BE6" BorderWidth="1" BackgroundColor="WhiteSmoke"/>
<Button TextColor="#006BE6" Text="3" Grid.Row="3" Grid.Column="3" Command="{Binding LoadNumberCommand}" CommandParameter="3" BorderColor="#006BE6" BorderWidth="1" BackgroundColor="WhiteSmoke"/>
<Button TextColor="#006BE6" Text="4" Grid.Row="4" Grid.Column="1" Command="{Binding LoadNumberCommand}" CommandParameter="4" BorderColor="#006BE6" BorderWidth="1" BackgroundColor="WhiteSmoke"/>
<Button TextColor="#006BE6" Text="5" Grid.Row="4" Grid.Column="2" Command="{Binding LoadNumberCommand}" CommandParameter="5" BorderColor="#006BE6" BorderWidth="1" BackgroundColor="WhiteSmoke"/>
<Button TextColor="#006BE6" Text="6" Grid.Row="4" Grid.Column="3" Command="{Binding LoadNumberCommand}" CommandParameter="6" BorderColor="#006BE6" BorderWidth="1" BackgroundColor="WhiteSmoke"/>
<Button TextColor="#006BE6" Text="7" Grid.Row="5" Grid.Column="1" Command="{Binding LoadNumberCommand}" CommandParameter="7" BorderColor="#006BE6" BorderWidth="1" BackgroundColor="WhiteSmoke"/>
<Button TextColor="#006BE6" Text="8" Grid.Row="5" Grid.Column="2" Command="{Binding LoadNumberCommand}" CommandParameter="8" BorderColor="#006BE6" BorderWidth="1" BackgroundColor="WhiteSmoke"/>
<Button TextColor="#006BE6" Text="9" Grid.Row="5" Grid.Column="3" Command="{Binding LoadNumberCommand}" CommandParameter="9" BorderColor="#006BE6" BorderWidth="1" BackgroundColor="WhiteSmoke"/>
<Button TextColor="#006BE6" Text="C" Grid.Row="6" Grid.Column="1" Command="{Binding LoadNumberCommand}" CommandParameter="C" BorderColor="#006BE6" BorderWidth="1" BackgroundColor="WhiteSmoke"/>
<Button TextColor="#006BE6" Text="0" Grid.Row="6" Grid.Column="2" Command="{Binding LoadNumberCommand}" CommandParameter="0" BorderColor="#006BE6" BorderWidth="1" BackgroundColor="WhiteSmoke"/>
<Button TextColor="#006BE6" Text="OK" Grid.Row="6" Grid.Column="3" Command="{Binding LoadNumberCommand}" CommandParameter="OK" BorderColor="#006BE6" BorderWidth="1" BackgroundColor="WhiteSmoke"/>
</Grid>
</StackLayout>
</ContentPage.Content>
一切正常,只是条目中的文本没有显示。我的想法是添加 4 位密码。绑定引脚从数字中获取值,但未显示在条目中。我不知道是什么问题。有人帮忙吗?
在 ViewModel 中添加 Pin 和 Command
public string pin;
public string Pin
{
get { return pin; }
set
{
if (pin != value)
{
pin = value;
SetProperty(ref pin, value);
OnPropertyChanged("Pin");
}
}
}
和命令
LoadNumberCommand = new Command(execute: async (value) => await ExecutePinElement(value));
解决方案
将您的条目IsReadOnly
属性设置为 false
或者
更改HorizontalOptions
到"FillAndExpand"
并添加HorizontalTextAlignment="Center"
推荐阅读
- javascript - Protractor getAttribute promise - 解析值
- excel - 创建一个新工作簿并将过滤后的数据复制到其中
- flutter - 如何在颤动中将图像作为状态栏的背景?
- django - 我需要一个真实的项目来练习 python 和 Django
- php - 没有得到正确的日期来显示昨天的日期
- java - 在 Spring Integration 中取消执行流程
- regex - 英国驾照正则表达式
- python - 如何插入包含数组的列表?
- eloquent - 如何从数据库中获取所有表名并对其进行分页
- angular - 如何使以前存在的项目/应用程序在 Angular 6 中响应