小编Rei*_*ter的帖子

在页面中水平居中DIV

我正在尝试将一个div集中,这是用于HTML5/JavaScript的Windows 8应用程序的Microsoft pubCenter AdControl.

    <div id="myAd" style="; top: 0%; width: 292px; height: 60px; z-index: 1"
        data-win-control="MicrosoftNSJS.Advertising.AdControl"
        data-win-options="{applicationId: 'exampleAdId', adUnitId: 'exampleAdUnit'}">
    </div>
Run Code Online (Sandbox Code Playgroud)

如何将div水平居中,使其始终位于页面中间?

html html5 microsoft-metro windows-8 winjs

11
推荐指数
2
解决办法
7万
查看次数

保存文件时出现UnauthorizedAccessException

我在Windows 8 C#应用程序中有以下代码,它从服务器获取图像并存储它:

        private async Task httpFetcher()
    {
        HttpClient httpClient = new HttpClient();
        HttpRequestMessage request = new HttpRequestMessage(
HttpMethod.Get, "http://www.example.com/fakeImageRotator.php"); // FOR EXAMPLE
        HttpResponseMessage response = await httpClient.SendAsync(request,
            HttpCompletionOption.ResponseHeadersRead);

        Uri imageUri;
        BitmapImage image = null;

        try
        {
            var imageFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(
         "test.png", CreationCollisionOption.ReplaceExisting);
            var fs = await imageFile.OpenAsync(FileAccessMode.ReadWrite);
            DataWriter writer = new DataWriter(fs.GetOutputStreamAt(0));
            writer.WriteBytes(await response.Content.ReadAsByteArrayAsync());
            await writer.StoreAsync();
            writer.DetachStream();
            await fs.FlushAsync();
            writer.Dispose();

            if (Uri.TryCreate(imageFile.Path, UriKind.RelativeOrAbsolute, out imageUri))
            {
                image = new BitmapImage(imageUri);
            }

        }
        catch (Exception e)
        {
            return;
        } …
Run Code Online (Sandbox Code Playgroud)

c# error-handling asynchronous unauthorizedaccessexcepti windows-8

6
推荐指数
1
解决办法
4059
查看次数

AudioPlaybackAgent中的定时器

我有一个使用的互联网广播应用程序BackgroundAudioPlayer.

我需要音频播放代理中的一个计时器,它将更新从Internet广播电台的API中提取的BAP当前播放曲目的曲目标题.

添加DispatcherTimer到音频播放代理程序给我一个跨线程异常,并使用:

Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                // Code
            });
Run Code Online (Sandbox Code Playgroud)

没工作.

我需要这里的代码,因为如果我将更新代码放在应用程序本身,当用户导航离开应用程序时,更新会停止(与Windows 8的行为非常不同).

我不能使用预定代理,因为它们每30分钟只运行一次(IIRC).

这是可能的还是不能在Windows Phone上完成?

c# dispatchertimer background-agents background-audio windows-phone-8

6
推荐指数
1
解决办法
173
查看次数

DataContractSerializer失败,空数据

我有一些Windows Phone 7的代码,用于RSS应用程序:

private RSSSettings DeserializeSettings(string data)
    {
        RSSSettings rsssettings;
        try
        {
            var ser = new DataContractSerializer(typeof(RSSSettings));
            using (var sr = new StringReader(data))
            using (var xr = XmlReader.Create(sr))
                rsssettings = (RSSSettings)ser.ReadObject(xr);
        }
        catch (Exception ex)
        {
            ex.ToString();
            rsssettings = new RSSSettings() { Version = -1 };
        }
        return rsssettings;
    }
Run Code Online (Sandbox Code Playgroud)

它在Windows Phone 7上完美运行.我将应用程序移植到Windows Phone 8,除了此代码段之外,应用程序中的其他所有内容都可以正常工作.

比较Windows Phone 7和8中发生的情况,WP8中的"rsssettings"在WP7中正确填充时保持为null.代码的这部分根本没有代码更改.

一切都是一样的,直到:

rsssettings = (RSSSettings)ser.ReadObject(xr);
Run Code Online (Sandbox Code Playgroud)

不会调用该异常.

任何人都知道如何解决这个令人沮丧的问题?

c# xml-serialization windows-phone-7 data-serialization windows-phone-8

5
推荐指数
1
解决办法
1302
查看次数

将 Base64 图像上传到 Azure Blob

我有以下 ASPX 标记:

<asp:Image ImageUrl="placeholder.png" runat="server" ID="plhdr" />
Run Code Online (Sandbox Code Playgroud)

该网页让用户上传一张图片,该图片通过一个 JavaScript 库进行处理,然后设置为上述控件的来源。JavaScript 将源设置为 Base64 字符串,如下所示:

数据:图像/jpeg;base64,/9j/4AAQ...

我在同一页面上有一个函数,用于将显示的图像上传到 Azure 存储,然后在 Azure SQL 中添加对它的引用。我在后面的代码中的代码是:

    StorageCredentials creden = new StorageCredentials(accountname, accesskey);
    CloudStorageAccount acc = new CloudStorageAccount(creden, useHttps: true);
    CloudBlobClient client = acc.CreateCloudBlobClient();
    CloudBlobContainer cont = client.GetContainerReference("testcont");
    cont.CreateIfNotExists();
    cont.SetPermissions(new BlobContainerPermissions
    {
        PublicAccess = BlobContainerPublicAccessType.Blob
    });
    CloudBlockBlob cblob = cont.GetBlockBlobReference("cblob");

    var imagesrc = plhdr.ImageUrl;

    cblob.UploadFromFile(@imagesrc);

    var imageUrl = cblob.Uri;
Run Code Online (Sandbox Code Playgroud)

“/”应用程序中的服务器错误。找不到路径“D:\Windows\system32\placeholder.png”的一部分。异常详细信息:System.IO.DirectoryNotFoundException:找不到路径“D:\Windows\system32\dist\img\fling\space.gif”的一部分。

在这一行:cblob.UploadFromFile(@imagesrc);

希望有人能指出我正确的方向。

c# asp.net azure azure-storage-blobs

2
推荐指数
1
解决办法
7961
查看次数