本文整理汇总了C#中Distance.BestMeasureAs方法的典型用法代码示例。如果您正苦于以下问题:C# Distance.BestMeasureAs方法的具体用法?C# Distance.BestMeasureAs怎么用?C# Distance.BestMeasureAs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Distance
的用法示例。
在下文中一共展示了Distance.BestMeasureAs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RefreshFromDistance
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);
}
}
}