// add geofence to listbox private void AddGeofenceToRegisteredGeofenceListBox(Geofence geofence) { GeofenceItem item = new GeofenceItem(geofence); // the registered geofence listbox is data bound // to the collection stored in the root page geofenceCollection.Insert(0, item); }
private void RefreshControlsFromGeofenceItem(GeofenceItem item) { if (null != item) { Id.Text = item.Id; Latitude.Text = item.Latitude.ToString(); Longitude.Text = item.Longitude.ToString(); Radius.Text = item.Radius.ToString(); SingleUse.IsChecked = item.SingleUse; if (0 != item.DwellTime.Ticks) { DwellTime.Text = item.DwellTime.ToString(); } else { DwellTime.Text = ""; } if (0 != item.Duration.Ticks) { Duration.Text = item.Duration.ToString(); } else { Duration.Text = ""; } if (0 != item.StartTime.Ticks) { DateTimeOffset dt = item.StartTime; StartTime.Text = formatterShortDateLongTime.Format(dt); } else { StartTime.Text = ""; } // Update flags used to enable Create Geofence button OnIdTextChanged(null, null); OnLongitudeTextChanged(null, null); OnLatitudeTextChanged(null, null); OnRadiusTextChanged(null, null); } }
/// <summary> /// This is the click handler for the 'Remove Geofence Item' button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnRemoveGeofenceItem(object sender, RoutedEventArgs e) { if (null != RegisteredGeofenceListBox.SelectedItem) { // get selected item GeofenceItem itemToRemove = RegisteredGeofenceListBox.SelectedItem as GeofenceItem; var geofence = itemToRemove.Geofence; // remove the geofence from the client side geofences collection Remove(geofence); // empty the registered geofence listbox and repopulate geofenceCollection.Clear(); FillRegisteredGeofenceListBoxWithExistingGeofences(); } }
void OnRegisteredGeofenceListBoxSelectionChanged(object sender, SelectionChangedEventArgs e) { IList <object> list = e.AddedItems; if (0 == list.Count) { // disable the remove button RemoveGeofenceItem.IsEnabled = false; } else { // enable the remove button RemoveGeofenceItem.IsEnabled = true; // update controls with the values from this geofence item // get selected item GeofenceItem item = RegisteredGeofenceListBox.SelectedItem as GeofenceItem; RefreshControlsFromGeofenceItem(item); DetermineCreateGeofenceButtonEnableState(); } }