That leaves Edit/Update Operator. Currently, the updateOperatorButton_Clicked does nothing...
Please copy following code in UpdateOperatorButton_Clicked
method of OperatorsPage.xaml.cs
private async void UpdateOperatorButton_Clicked(object sender, EventArgs e)
{
if (SelectModel != null)
{
var operatorInfoPage = new OperatorInfoPage(SelectModel);
operatorInfoPage.ReturnValue += delegate (object s, OperatorModel operatorModel)
{
BackCall(s, operatorModel);
};
await Navigation.PushModalAsync(operatorInfoPage);
}
else
{
await DisplayAlert("info", "please select item", "OK");
}
}
Here is code about OperatorInfoPage.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"
x:Class="App94.OperatorInfoPage">
<ContentPage.Content>
<Grid BackgroundColor="White">
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="30"/>
<RowDefinition Height="10"/>
<RowDefinition Height="*"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="50"/>
</Grid.ColumnDefinitions>
<Button
x:Name="BackButton"
Text="Back"
Grid.Row="0"
Grid.Column="0"
Grid.ColumnSpan="3"
TextColor="Black"
FontAttributes="Bold"
HeightRequest="40"
VerticalOptions="CenterAndExpand"
HorizontalOptions="End"
Margin="0,0,20,0"
Clicked="BackButton_Clicked"/>
<Image
Source="hfn256"
Margin="2"
Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="3"
HorizontalOptions="Center"
BackgroundColor="Transparent"/>
<Label
Text="Update Operator"
FontSize="Large"
TextColor="Black"
FontAttributes="Bold"
Padding =" 0, 0, 0, 0"
Grid.Row="2"
Grid.Column="0"
Grid.ColumnSpan="3"
HorizontalOptions="Center"
VerticalOptions="End"
BackgroundColor="Transparent"/>
<ScrollView Orientation="Vertical"
Grid.Row="4" Grid.Column="0"
Grid.ColumnSpan="3">
<Grid BackgroundColor="White" >
<Grid.RowDefinitions>
<RowDefinition Height="60"/>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
<RowDefinition Height="100"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="80"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label
x:Name="NameLabel"
Text="Name: "
TextColor="Black"
FontSize="Medium"
FontAttributes="Bold"
Grid.Row="0"
Margin="40, 0, 0, 0"
HorizontalOptions="Start"
VerticalOptions="Center"/>
<Entry
x:Name="NameEntry"
Text="{Binding opm1.OperatorName}"
Placeholder="Enter a name / callsign"
PlaceholderColor="LightGray"
TextColor="DarkBlue"
FontSize="Medium"
Keyboard="Plain"
Grid.Row="0"
Grid.Column="1"
Grid.ColumnSpan="2"
Margin="0, 0, 30, 0"/>
<Label
x:Name="PhoneLabel"
Text="Phone: +"
TextColor="Black"
FontSize="Medium"
FontAttributes="Bold"
Grid.Row="1"
Grid.Column="0"
Margin="40, 0, 0, 0"
HorizontalOptions="Start"
VerticalOptions="Center"/>
<!-- <Entry
x:Name="PhoneCountryEntry"
Text="{Binding }"
Placeholder="Country"
PlaceholderColor="LightGray"
TextColor="DarkBlue"
FontSize="Medium"
Keyboard="Numeric"
Grid.Row="1"
Grid.Column="1"
Margin="0, 0, 0, 0"/> -->
<Entry
x:Name="PhoneEntry"
Text="{Binding opm1.OperatorPhone}"
Placeholder="Phone (inc. Country - no spaces)"
PlaceholderColor="LightGray"
TextColor="DarkBlue"
FontSize="Medium"
Keyboard="Numeric"
Grid.Row="1"
Grid.Column="1"
Grid.ColumnSpan="2"
Margin="0, 0, 30, 0"/>
<Label
x:Name="EmailLabel"
Text="Email: "
TextColor="Black"
FontSize="Medium"
FontAttributes="Bold"
Grid.Row="2"
Margin="40, 0, 0, 0"
HorizontalOptions="Start"
VerticalOptions="Center"/>
<Entry
x:Name="EmailEntry"
Text="{Binding opm1.OperatorEmail}"
Placeholder="Enter Email..."
PlaceholderColor="LightGray"
TextColor="DarkBlue"
FontSize="Medium"
Keyboard="Email"
Grid.Row="2"
Grid.Column="1"
Grid.ColumnSpan="2"
Margin="0, 0, 30, 0"/>
<Label
x:Name="AvatarLabel"
Text="Avatar: "
TextColor="Black"
FontSize="Medium"
FontAttributes="Bold"
Grid.Row="3"
Margin="40, 0, 0, 0"
HorizontalOptions="Start"
VerticalOptions="Center"/>
<Entry
x:Name="AvatarEntry"
Text="{Binding opm1.OperatorAvatar}"
Placeholder="Enter Avatar URL..."
PlaceholderColor="LightGray"
TextColor="DarkBlue"
FontSize="Medium"
Keyboard="Plain"
Grid.Row="3"
Grid.Column="1"
Grid.ColumnSpan="2"
Margin="0, 0, 30, 0"/>
<Button
x:Name="OKButton"
Text="OK"
TextColor="Black"
FontAttributes="Bold"
HorizontalOptions="Start"
VerticalOptions="Center"
WidthRequest="100"
HeightRequest="40"
Margin="0, 20, 0, 0"
Grid.Row="4"
Grid.Column="1"
Clicked="OKButton_Clicked"/>
<Button
x:Name="CancelButton"
Text="Cancel"
TextColor="Black"
FontAttributes="Bold"
HorizontalOptions="End"
VerticalOptions="Center"
WidthRequest="100"
HeightRequest="40"
Margin="0, 20, 40, 0"
Grid.Row="4"
Grid.Column="2"
Clicked="CancelButton_Clicked"/>
</Grid>
</ScrollView>
</Grid>
</ContentPage.Content>
</ContentPage>
Here is code about OperatorInfoPage.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace App94
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class OperatorInfoPage : ContentPage
{
// OperatorViewModel ovm;
// OperatorModel opm;
// public OperatorModel opm1 { get; set; }
OperatorModel _opm1 ;
public OperatorModel opm1
{
get
{
return _opm1;
}
set
{
if (_opm1 != value)
{
_opm1 = value;
OnPropertyChanged("opm1");
}
}
}
int SelectItemIndex;
public EventHandler<OperatorModel> ReturnValue;
public OperatorInfoPage(OperatorModel opm)
{
// add a bit of padding to cater to the "notch" on the iPhone.
if (Device.RuntimePlatform == Device.iOS)
{
Padding = new Thickness(0, 40, 0, 0);
}
InitializeComponent();
SelectItemIndex= OperatorViewModel.OperatorList.IndexOf(opm);
// ovm = _ovm;
// opm = ovm.SelectedOperator;
this.opm1 = opm;
BindingContext = this;
}
private async void BackButton_Clicked(object sender, EventArgs e)
{
await Navigation.PopModalAsync();
}
private async void OKButton_Clicked(object sender, EventArgs e)
{
OperatorViewModel.OperatorList[SelectItemIndex].OperatorName = opm1.OperatorName;
OperatorViewModel.OperatorList[SelectItemIndex].OperatorPhone = opm1.OperatorPhone;
OperatorViewModel.OperatorList[SelectItemIndex].OperatorEmail = opm1.OperatorEmail;
OperatorViewModel.OperatorList[SelectItemIndex].OperatorAvatar = opm1.OperatorAvatar;
// OperatorViewModel.OperatorList.Add(opm1);
OperatorModel operatorModel = opm1;
EventHandler<OperatorModel> handler = ReturnValue;
if (handler != null)
{
handler(this, operatorModel);
}
await Navigation.PopModalAsync();
}
private async void CancelButton_Clicked(object sender, EventArgs e)
{
await Navigation.PopModalAsync();
}
}
}