All fields are marked as TwoWay on databinding, but its obvious I have something wrong. What I have is a page showing a view to add new Devices on one side of the view, and a list of Devices on the other side.. What I'm trying to do is when selecting an item from listview, it will update values within the TextBox for viewing and editing purposes.
The Save option (not shown in Code Below) currently works when I create a new Device, and will refresh the list. however, right now I'm Going back a Frame when complete. What I would like to do is refresh ListView when I click save.
Values from XAML page
<TextBox PlaceholderText="Host Name" Text="{x:Bind ViewModel.HostName, Mode=TwoWay}" Name="hostNameTB" AcceptsReturn="True" />
<TextBox PlaceholderText="Drive Model" Text="{x:Bind ViewModel.DriveModel, Mode=TwoWay}" Name="driveModelTB" />
<TextBox PlaceholderText="Drive SN" Text="{x:Bind ViewModel.DriveSN, Mode=TwoWay}" Name="driveSNTB" AcceptsReturn="True" InputScope="Digits"/>
Code from ViewModel
private Device _ActiveDevice;
private int _HostName;
//All Variables Created for DataBinding to XAML page
//public int HostName { get { return _HostName; } set { _ActiveDevice.HostName = value; } }
public int HostName { get; set; }
public string DriveModel { get; set; }
public string DriveSN { get; set; }
public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary<string, object> suspensionState)
{
Value = (suspensionState.ContainsKey(nameof(Value))) ? suspensionState[nameof(Value)]?.ToString() : parameter?.ToString();
await Task.CompletedTask;
var uri = new Uri("http://localhost:2463/api/Devices");
HttpClient client = new HttpClient();
try
{
var JsonResponse = await client.GetStringAsync(uri);
var devicesResult = JsonConvert.DeserializeObject<List<Device>>(JsonResponse);
Devices = devicesResult;
_ActiveDevice = JsonConvert.DeserializeObject<List<Device>>(JsonResponse)[0];
}
catch
{
MessageDialog dialog = new MessageDialog("Unable to Access WebService at this Time!");
await dialog.ShowAsync();
}
//client.Dispose();
}
public void deviceList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var device = ((sender as ListView).SelectedItem as Device);
_ActiveDevice = device;
HostName = device.HostName;
DriveModel = device.DriveModel;
DriveSN = device.DriveSN;
}