0

C#代码如下

public partial class zoom1: PhoneApplicationPage
{
    // Constructor
    public zoom1()
    {
        InitializeComponent(); //the erroe is shown here
    }

    private async void SetBackground1(object sender, RoutedEventArgs e)
    {
        if (await LockScreenManager.RequestAccessAsync() == LockScreenRequestResult.Granted)
        {
            var uri = new Uri("ms-appx:///Assets/LockScreens/People/1.jpg", UriKind.Absolute);
            LockScreen.SetImageUri(uri);
            MessageBox.Show("Your new lockscreen background has been set.");
        }
        else
        {
            MessageBox.Show("You said no, so I can't update your background.");
        }
    }
}

将 click="" 添加到 AppBarButton 后生成错误。XAML 代码如下

<phone:PhoneApplicationPage.ApplicationBar>
    <shell:ApplicationBar IsVisible="True" Opacity="0.5" IsMenuEnabled="True">
        <shell:ApplicationBarIconButton IconUri="Assets/Buttons/Check.png" Text="Set" Click="SetBackground1"/>
    </shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
4

1 回答 1

0

你试过没有异步吗?此外,文档中的示例使用EventArgs而不是RoutedEventArgs,但我不确定这是否会导致您看到的异常。

于 2013-09-11T04:49:21.780 回答