首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >搜索位置时窗口电话进度条

问搜索位置时窗口电话进度条
EN

Stack Overflow用户
提问于 2014-08-06 15:52:00
回答 1查看 109关注 0票数 1

我尝试激活一个进度条,而应用程序正在搜索位置(按下按钮后),我如何解决它最好的方式?

最好的方法是得到一个如果在那里,惠特,我得到(严格的)数据,从地理坐标和检查。

代码语言:javascript
复制
private async void Ellipse_Tap (object sender, System.Windows.Input.GestureEventArgs e)
{
    Geolocator geolocator = new Geolocator();
    //Set his accuracy in Meters 
    geolocator.DesiredAccuracyInMeters = 50;
    try
    {
        //The await guarantee the calls  to be returned on the thread from which they were called
        //Since it is call directly from the UI thread, the code is able to access and modify the UI directly when the call returns.
        Geoposition geoposition = await geolocator.GetGeopositionAsync(
            maximumAge: TimeSpan.FromMinutes(5),
            timeout: TimeSpan.FromSeconds(10)
            );

        //Relativer Nullpunkt

        delta_y = geoposition.Coordinate.Latitude - y;
        delta_x = geoposition.Coordinate.Longitude - x;

        Path.Visibility = Visibility.Visible;

    }
    //If an error is catch 2 are the main causes: the first is that you forgot to includ ID_CAP_LOCATION in your app manifest. 
    //The second is that the user doesn't turned on the Location Services
    catch (Exception ex)
    {
        if ((uint)ex.HResult == 0x80004004)
        {
            MessageBox.Show("Location is disabled in phone settings.");
            return;
            //Application.Current.Terminate();
        }
        //else
        {
            // something else happened during the acquisition of the location
        }
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-06 16:37:51

假设您在SystemTry中使用的是SystemTry,那么向OnNavigatedTo方法中添加以下内容

代码语言:javascript
复制
protected override void OnNavigatedTo(NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
    SystemTray.ProgressIndicator = new ProgressIndicator();
}

然后创建此方法来设置ProgressIndicator。

代码语言:javascript
复制
private void DisplayProgressIndicator(bool isvisible, string message = "")
{
    SystemTray.ProgressIndicator.Text = message;
    SystemTray.ProgressIndicator.IsIndeterminate = isvisible;
    SystemTray.ProgressIndicator.IsVisible = isvisible;
}

然后使用在Eclips_Tap方法中创建的方法。

代码语言:javascript
复制
private async void Ellipse_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
    Geolocator geolocator = new Geolocator();
    geolocator.DesiredAccuracyInMeters = 50;
    try
    {
        DisplayProgressIndicator(true, "Finding current location..."); // < SET THE PROGRESS INDICATOR

        Geoposition geoposition = await geolocator.GetGeopositionAsync(
            maximumAge: TimeSpan.FromMinutes(5),
            timeout: TimeSpan.FromSeconds(10)
            );

        delta_y = geoposition.Coordinate.Latitude - y;
        delta_x = geoposition.Coordinate.Longitude - x;

        Path.Visibility = Visibility.Visible;

        DisplayProgressIndicator(false); // << UNSET PROGRESS INDICATOR

    }
    catch (Exception ex)
    {
        if ((uint)ex.HResult == 0x80004004)
        {
            MessageBox.Show("Location is disabled in phone settings.");
            return;
        }                
    }
}

希望这有帮助..。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25164856

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档