标签: windows-runtime

如何将异步事件处理程序连接到WinRT中的非异步事件?

我有一个从Windows.UI.Xaml.Controls.Page派生的页面,我想做这样的事情:

Loaded += OnPageLoaded;
Run Code Online (Sandbox Code Playgroud)

哪里:

private async Task OnPageLoaded(object sender, RoutedEventArgs e)
{
   await SomeAsync();
}
Run Code Online (Sandbox Code Playgroud)

甚至可以把它连接起来吗?

我明白了:

error CS0407: 'System.Threading.Tasks.Task 
    MyApp.MyPage.OnPageLoaded(object, Windows.UI.Xaml.RoutedEventArgs)' 
    has the wrong return type
Run Code Online (Sandbox Code Playgroud)

Msdn在事件和路由事件概述中提到了类似的内容,但未能使其工作.

谢谢!

c# asynchronous windows-8 windows-runtime

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

如何获得WinRT中的Key

我曾使用OnTextInput Event来获取WPF/Silverlight中最终用户的Key Pressed,但是在WinRT的情况下,我没有这样的事件,我对KeyDown事件感到震惊.虽然事件返回用户按下的键,但是当事件返回VirtualKey Enum时,我无法区分大小写(即小写或大写).

有没有可能的解决方法?

问候

c# events windows-runtime winrt-xaml

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

如何暂时禁用多语言应用工具包?

我有一个Windows Store应用程序(Windows 8),当前正在使用“多语言工具包”将许多字符串翻译成多种语言。不幸的是,这样做使我的应用程序的每个构建都需要6分钟以上的时间!这对我的应用程序进行了细微的改动,使我的工作流程彻底瘫痪。

有什么办法可以在不影响我的任何语言文件的情况下暂时禁用Multilingual App Toolkit,以便我可以进行快速开发,但仍然能够像以前一样使用Multilingual Toolkit?

c# multilingual windows-8 windows-runtime windows-store-apps

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

如何获得容器(即网格)以适应其内容的旋转大小?

(Windows 8.1,Windows应用商店应用)

我想将旋转的文本放在容器(例如Grid)中,让容器从旋转的文本中获取其尺寸.然而...

这段代码:

<Canvas Background="Gray">

    <Grid
        Canvas.Left="100"
        Canvas.Top="100"
        Background="LightGray">
        <TextBlock Text="Text rotated 270º">
            <TextBlock.RenderTransform>
                <RotateTransform Angle="270" />
            </TextBlock.RenderTransform>
        </TextBlock>
    </Grid>

<Canvas>
Run Code Online (Sandbox Code Playgroud)

......像这样呈现:

在此输入图像描述

我希望网格在应用旋转后从TextBlock获取宽度和高度.但是,在应用旋转之前,网格似乎从TextBlock获取其尺寸.

如何获得容器(即网格)以适应其内容的旋转大小(即TextBlock)?

xaml windows-8 windows-runtime windows-store-apps windows-8.1

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

使用NavigateToLocalStreamUri的WebView实际上并不导航

我有一个WebView,我用它来从ApplicationData.Current.LocalFolder加载本地文件.我做了一个在WebView上调用Navigate的方法

public override void BrowserNavigateLocal(string fileName)
{
   Uri uri = browser.BuildLocalStreamUri("page", fileName);
   browser.NavigateToLocalStreamUri(uri, new MyStreamUriResolver());
}
Run Code Online (Sandbox Code Playgroud)

我的IUriToStreamResolver看起来像这样

public sealed class MyStreamUriResolver : IUriToStreamResolver
{
    public IAsyncOperation<IInputStream> UriToStreamAsync(Uri uri)
    {
        lock (this)
        {
            if (uri == null)
            {
                throw new Exception();
            }
            string path = uri.AbsolutePath;
            return GetContent(path).AsAsyncOperation();
        }
    }

    private async Task<IInputStream> GetContent(string path)
    {
        try
        {

            Uri localUri = new Uri("ms-appdata:///local/HTML" + path);

            //StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(localUri);
            //IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);

            StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(localUri).AsTask().ConfigureAwait(false);
            IRandomAccessStream …
Run Code Online (Sandbox Code Playgroud)

c# xaml windows-runtime windows-8.1

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

如何在两个页面之间进行动画过渡?

我正在构建一个Windows 8.1应用程序,我想知道如何在两个页面之间显示动画过渡.现在我只是使用Navigate方法来更改页面,但没有动画过渡.

this.Frame.Navigate(typeof(MyPage));
Run Code Online (Sandbox Code Playgroud)

谢谢!

c# windows-runtime winrt-xaml

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

获取当前呼叫堆栈

是否有可能在Windows应用商店中获取当前的调用堆栈,而不会抛出异常?

我找到了这个答案,但它不适用于Windows应用商店.

为什么我需要这个

我需要得到调用堆栈,因为我有一个DirectX纹理内存泄漏.

我想在分配它时将调用堆栈附加到我的纹理.在一些程序使用之后,我打印了尚未解除分配的所有纹理的callstack.

应该很容易看到我忘记取消分配纹理的位置.

c# callstack windows-8 windows-runtime windows-store-apps

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

读取页面导航上传递的字符串数组

当我从WP8.1中的另一个页面传递一个字符串时,我目前不确定如何读取参数.这实际上是我用来在导航到另一个页面时传递参数的代码:

String[] parameters = new String[3];
parameters[0] = ReliabilitySwitch.IsEnabled.ToString();
if (i != 2)
{
    parameters[1] = UnitsList.SelectedItem.ToString();
    parameters[2] = MethodSwitch.IsEnabled.ToString();
}
else
{
    parameters[1] = "2";
}    
Frame.Navigate(typeof(Nav),parameters);
Run Code Online (Sandbox Code Playgroud)

这说,我不知道如何从其他页面读取我传递的参数.我知道如何读取,例如,一个整数值.我试过像这样读这个参数,但我肯定在这个过程中遗漏了一些数据:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    String parameters;
    parameters = e.Parameter.ToString();
}
Run Code Online (Sandbox Code Playgroud)

c# navigation windows-runtime windows-store-apps windows-phone-8.1

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

在WP 8.1中访问Assets文件夹时出现异常

我正在尝试将应用程序从Windows Phone Silverlight 8.0升级到8.1.当我尝试访问8.1上的"Assets"文件夹时,我遇到了异常.我能够在一个示例项目中重现这一点,该项目在定位8.0时工作正常,但在升级到8.1时会产生异常.

以下是示例应用程序MainPage的XAML:

<phone:PhoneApplicationPage
    x:Class="PhoneApp1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
            <TextBlock Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Button Content="Get Assets" HorizontalAlignment="Center" VerticalAlignment="Center" Click="Button_Click"/>
        </Grid>
    </Grid>

</phone:PhoneApplicationPage>
Run Code Online (Sandbox Code Playgroud)

这是MainPage代码隐藏:

using System;
using System.Diagnostics;
using System.Windows;
using Microsoft.Phone.Controls;
using Windows.Storage;

namespace PhoneApp1
{
    public partial class MainPage …
Run Code Online (Sandbox Code Playgroud)

windows-runtime windows-phone-8 windows-phone-8.1

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

C#/ XAML winRT应用程序导出PDF

如何在winRT应用程序中生成pdf?我正在使用iTextSharp在windows store应用程序中生成pdf,但winRT没有filestream,filemode或filedirectory.救命

这是我的代码:

iTextSharp.text.pdf.PdfWriter writer = 
    iTextSharp.text.pdf.PdfWriter.GetInstance(
        doc, new System.IO.FileStream(System.IO.Directory.GetCurrentDirectory() +
                                      "\\ScienceReport.pdf", System.IO.FileMode.Create
        )
    );
Run Code Online (Sandbox Code Playgroud)

c# winapi xaml windows-runtime

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