Я делаю Pin-валидатор при запуске приложения. Это мой код:
<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 ди git пин. Binding Pin получает значения из чисел, но не отображается в записи. Я не знаю в чем проблема. Кто-нибудь поможет?
В ViewModel в добавлены Pin и Command
public string pin;
public string Pin
{
get { return pin; }
set
{
if (pin != value)
{
pin = value;
SetProperty(ref pin, value);
OnPropertyChanged("Pin");
}
}
}
и Command
LoadNumberCommand = new Command(execute: async (value) => await ExecutePinElement(value));