private void RefreshFromDistance(Distance newDistance) { if (newDistance == null) { if (WherigoObject == null) { // Shows the control in a state displaying that the distance is undefined. DistanceText.Text = "In Range"; VisualStateManager.GoToState(this, this.UnknownState.Name, true); } else { // Shows some context: the thing's container, if there is one. if (WherigoObject.Container == null) { // No clue, let's just show "In Range". DistanceText.Text = "In Range"; VisualStateManager.GoToState(this, this.UnknownState.Name, true); } else { // We have a name. DistanceText.Text = "By " + WherigoObject.Container.Name; VisualStateManager.GoToState(this, this.UnknownState.Name, true); } } } else { // Tries to retrieve the new distance value. // In some rare cases this may fail. double distanceValue = 0; try { distanceValue = newDistance.Value; } catch (InvalidOperationException) { // This probably means that an error occurred while computing // or retrieving the value. Let's display "Unknown" as a distance // text. DistanceText.Text = "Unknown"; return; } // Are we inside or outside? if (distanceValue == 0) { DistanceText.Text = "Here"; VisualStateManager.GoToState(this, this.InsideState.Name, true); } else { DistanceText.Text = newDistance.BestMeasureAs(App.Current.Model.Settings.LengthUnit); VisualStateManager.GoToState(this, this.OutsideState.Name, true); } } }
private void RefreshFromDistance(Distance newDistance) { if (newDistance == null) { if (WherigoObject == null) { // Shows the control in a state displaying that the distance is undefined. DistanceText.Text = "In Range"; VisualStateManager.GoToState(this, this.UnknownState.Name, true); } else { // Shows some context: the thing's container, if there is one. if (WherigoObject.Container == null) { // No clue, let's just show "In Range". DistanceText.Text = "In Range"; VisualStateManager.GoToState(this, this.UnknownState.Name, true); } else { // We have a name. DistanceText.Text = "By " + WherigoObject.Container.Name; VisualStateManager.GoToState(this, this.UnknownState.Name, true); } } } else { // Tries to retrieve the new distance value. // In some rare cases this may fail. double distanceValue = 0; try { distanceValue = newDistance.Value; } catch (InvalidOperationException) { // This probably means that an error occurred while computing // or retrieving the value. Let's display "Unknown" as a distance // text. DistanceText.Text = "Unknown"; return; } // Are we inside or outside? if (distanceValue == 0) { DistanceText.Text = "Here"; VisualStateManager.GoToState(this, this.InsideState.Name, true); } else { DistanceText.Text = newDistance.BestMeasureAs(DistanceUnit.Meters); VisualStateManager.GoToState(this, this.OutsideState.Name, true); } } }