Не уверен, как это происходит, но два моих элемента Entry замораживают все приложение, когда их текст связан. По сути, они выглядят так же, как и везде. В приложении используются записи, с той лишь разницей, что при включении приложение зависает. Просто не имеет смысла, почему они ломаются, но другие, которые настроены точно так же, не делают. Будем благодарны за любую помощь, совет или предложение!
Обидные записи:
<Label Margin="3">Professor Phone</Label>
<Entry Text="{Binding ProfessorPhone}" Placeholder="Professor Email" Margin="3" />
<Label Margin="3">Professor Email</Label>
<Entry Text="{Binding ProfessorEmail}" Placeholder="Professor Phone" />
Просмотр:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="TermManager.Views.CourseDetailView">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Update" />
</ContentPage.ToolbarItems>
<ContentPage.Content>
<ScrollView>
<StackLayout>
<Label Text="Course Details" VerticalOptions="Center" HorizontalTextAlignment="Center" IsVisible="true" FontSize="Large" FontAttributes="Bold" TextColor="DarkBlue" Margin="10" />
<Label Margin="3">Course Title</Label>
<Entry Text="{Binding CourseTitle}" Placeholder="Course Title" Margin="3" />
<Label Margin="3">Start Date</Label>
<DatePicker Date="{Binding StartCourseDate}" Margin="3" />
<Label Margin="3">End Date</Label>
<DatePicker Date="{Binding EndCourseDate}" Margin="3" />
<Picker SelectedItem="{Binding CourseStatus}" Title="Course Status" Margin="3" TitleColor="DarkBlue">
<Picker.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>in progress</x:String>
<x:String>completed</x:String>
<x:String>dropped</x:String>
<x:String>plan to take</x:String>
</x:Array>
</Picker.ItemsSource>
</Picker>
<Label Margin="3">Professor Name</Label>
<Entry Text="{Binding ProfessorName}" Placeholder="Professor's Name" Margin="3" />
<Label Margin="3">Professor Email</Label>
<Entry Text="{Binding ProfessorPhone}" Placeholder="Professor Email" Margin="3" />
<Label Margin="3">Professor Phone</Label>
<Entry Text="{Binding ProfessorEmail}" Placeholder="Professor Phone" />
</StackLayout>
</ScrollView>
</ContentPage.Content>
Код сзади:
using System;
using System.Collections.Generic;
using TermManager.Models;
using TermManager.ViewModels;
using Xamarin.Forms;
namespace TermManager.Views
{
public partial class CourseDetailView : ContentPage
{
protected Course Course = new Course();
public CourseDetailView(Course course)
{
InitializeComponent();
BindingContext = new CourseDetailViewModel(Navigation, course);
}
}
}
ViewModel:
using System;
using Xamarin.Forms;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using TermManager.Models;
namespace TermManager.ViewModels
{
public class CourseDetailViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public Command UpdateCourse { get; private set; }
protected readonly INavigation Nav;
protected int _courseId;
protected int _termId;
protected string _courseTitle;
protected DateTime _startCourseDate;
protected DateTime _endCourseDate;
protected string _courseStatus;
protected string _name;
protected string _email;
protected string _phone;
public int CourseId
{
get => _courseId;
set
{
_courseId = value;
OnPropertyChanged();
}
}
public int TermId
{
get => _termId;
set
{
_termId = value;
OnPropertyChanged();
}
}
public string CourseTitle
{
get => _courseTitle;
set
{
_courseTitle = value;
OnPropertyChanged();
}
}
public DateTime StartCourseDate
{
get => _startCourseDate;
set
{
_startCourseDate = value;
OnPropertyChanged();
}
}
public DateTime EndCourseDate
{
get => _endCourseDate;
set
{
_endCourseDate = value;
OnPropertyChanged();
}
}
public string CourseStatus
{
get => _courseStatus;
set
{
_courseStatus = value;
OnPropertyChanged();
}
}
public string ProfessorName
{
get => _name;
set
{
_name = value;
OnPropertyChanged();
}
}
public string ProfessorEmail
{
get => ProfessorEmail;
set
{
_email = value;
OnPropertyChanged();
}
}
public string ProfessorPhone
{
get => ProfessorPhone;
set
{
_phone = value;
OnPropertyChanged();
}
}
public CourseDetailViewModel(INavigation nav, Course course = null)
{
Nav = nav;
if (course != null)
{
_courseId = course.CourseId;
_termId = course.TermId;
_courseTitle = course.CourseTitle;
_courseStatus = course.CourseStatus;
_startCourseDate = course.StartCourseDate;
_endCourseDate = course.EndCourseDate;
_name = course.ProfessorName;
_email = course.ProfessorEmail;
_phone = course.ProfessorPhone;
}
}
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}