小编Rom*_*asz的帖子

Windows Phone 8.1中的ListView在滚动浏览长列表时抖动(XAML)

我在Windows Phone 8.1应用程序中滚动浏览ListViews时遇到问题.短列表滚动得很好,滚动顺畅但是很快虚拟化就会在整个ListView"摆动"中向左轻微踢,但是明显足以令人讨厌.

我已经尝试删除所有过渡到没有效果,以及项目加载增加到没有成功.将项目面板设置为StackPanel(删除虚拟化)可以解决问题,但不是更可取.

我的列表视图绑定到BasicView模板附带的DefaultViewModel中的属性.

我做错了什么以及导致我的ListViews出现这种行为的原因是什么?

XAML:

<ListView x:Name="searchResultsList" IsItemClickEnabled="True" ItemClick="ListView_ItemClick" ItemsSource="{Binding searchResults}">
   <ListView.ItemContainerStyle>
      <Style TargetType="ListViewItem">
          <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
          <Setter Property="Margin" Value="0,0,0,20" />
      </Style>
   </ListView.ItemContainerStyle>
   <ListView.ItemTemplate>
      <DataTemplate>
          <Grid>
             <Grid.ColumnDefinitions>
                <ColumnDefinition Width="80" />
                <ColumnDefinition Width="10" />
                <ColumnDefinition Width="*" />
             </Grid.ColumnDefinitions>

             <Border Width="80" Height="80">
                <Image Source="{Binding Image}" />
             </Border>

             <StackPanel Grid.Column="2">
                <TextBlock Text="{Binding PodcastTitle}" TextWrapping="WrapWholeWords" FontSize="{StaticResource TextStyleExtraLargeFontSize}" />
                <TextBlock Text="{Binding LastUpdated, Converter={StaticResource dateConverter}}" Style="{ThemeResource ListViewItemSubheaderTextBlockStyle}" />
                <TextBlock Text="{Binding PodcastArtist}" TextWrapping="WrapWholeWords" Style="{ThemeResource ListViewItemContentTextBlockStyle}" />
             </StackPanel>
           </Grid>
       </DataTemplate>
   </ListView.ItemTemplate>
 </ListView>
Run Code Online (Sandbox Code Playgroud)

c# xaml windows-runtime windows-phone-8.1

24
推荐指数
2
解决办法
6798
查看次数

在.Net native中的线程池上运行异步任务的性能很差

我发现托管vs .Net本机代码有一个奇怪的区别.我有一个繁重的工作重定向到线程池.当在托管代码中运行应用程序时,一切都运行顺畅,但是一旦我打开本机编译 - 任务运行速度慢几十倍,以至于它挂起UI线程(我猜CPU是如此过载).

以下是调试输出的两个屏幕截图,左侧的屏幕截图来自托管代码,右侧的屏幕截图来自本机编译.正如您所看到的,UI任务所消耗的时间在两种情况下几乎相同,直到启动线程池作业时 - 然后在托管版本中UI经过的时间增长(实际上UI被阻止,您无法采取任何操作).线程池工作的时间不言自明.

管理本地人

重现问题的示例代码:

private int max = 2000;
private async void UIJob_Click(object sender, RoutedEventArgs e)
{
    IProgress<int> progress = new Progress<int>((p) => { MyProgressBar.Value = (double)p / max; });
    await Task.Run(async () => { await SomeUIJob(progress); });
}

private async Task SomeUIJob(IProgress<int> progress)
{
    Stopwatch watch = new Stopwatch();
    watch.Start();
    for (int i = 0; i < max; i++)
    {
        if (i % 100 == 0) { Debug.WriteLine($"     UI time elapsed => {watch.ElapsedMilliseconds}"); watch.Restart(); } …
Run Code Online (Sandbox Code Playgroud)

c# async-await .net-native win-universal-app uwp

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

Windows Store Universal App中的字体大小缩放(W8.1 + WP8.1)

如何在Windows应用商店通用应用程序(W8.1 + WP8.1)中缩放文本?基本上,无论使用哪种设备/分辨率,应用程序看起来都应该相同.目前的情况是布局(基于动态网格的布局)和图像比文本(字体大小)更好地缩放.

显示的文字看起来很适合WVGA分辨率(480×800),但对于1080p分辨率来说却非常小.

我已经阅读了许多内容,例如 缩放到像素密度的指南支持多种屏幕尺寸的指南

但我仍然不知道如何扩展文本以保持可读性,无论显示分辨率/ DPI.

当然,我可以编写一个使用DisplayInformation.ResolutionScale属性将字体大小转换为适当值的类.

例:

  • 带有ScaleFactor 1x的WVGA上的FontSize 16等于FontSize 16
  • 带有ScaleFactor 1.6x的WXGA上的FontSize 16等于FontSize 25,6
  • 带有ScaleFactor 1.5x的7​​20p上的FontSize 16等于FontSize 24
  • 带有ScaleFactor 2.25x的1080p上的FontSize 16等于FontSize 36

但我不确定这是否适用于所有情况.有没有更好的方法呢?我认为这样的常见任务可以通过一些内置功能来执行.

免责声明:这是(希望)不是"让我谷歌这个为你问题"我发现大量的页面是关于缩放,但它们都覆盖布局或图像.但我找不到任何有关字体大小缩放的信息.如果我错过了什么,请原谅我.


编辑:我很害怕,我没有清楚地表达问题:(左边是WVGA,右边是1080p) WVGA与1080p

xaml windows-8.1 windows-phone-8.1 win-universal-app windows-8.1-universal

20
推荐指数
3
解决办法
8590
查看次数

Windows Phone App for Windows Phone上的照片捕获

好吧,我的问题很简单:
我如何拍摄照片使用Windows Store AppWindows Phone 8.1,在使用相机?
MSDN上的示例使用Windows.Media.Capture.CameraCaptureUI,在Windows Phone上无法使用,或者用于Silverlight.
我无法使用Windows运行时专门为Windows Phone应用找到任何文档或示例.
如果有人知道,或者甚至有这方面的文件,我会很高兴.

c# windows xaml windows-phone-8.1 win-universal-app

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

扩展执行无法正常工作?

我无法ExtendedExecution正常工作.问题是Revoked在执行完成之前不会触发事件.如果我们采样:

private async void OnSuspending(object sender, SuspendingEventArgs e)
{
    Debug.WriteLine("Suspending in app");
    var deferral = e.SuspendingOperation.GetDeferral();
    using (var session = new ExtendedExecutionSession())
    {
        session.Reason = ExtendedExecutionReason.SavingData;
        session.Description = "Upload Data";
        session.Revoked += (s, a) => { Debug.WriteLine($"Extended execution revoked because of {a.Reason}"); };
        var result = await session.RequestExtensionAsync();
        if (result == ExtendedExecutionResult.Denied) Debug.WriteLine("Extended execution failed");
        else
        {
            Debug.WriteLine("Executing");
            await Task.Run(() => { Task.Delay(9000).Wait(); Debug.WriteLine("Finished the task"); });
            Debug.WriteLine("Executing finished");
        }
        Debug.WriteLine("Suspending after execution");
    }
    deferral.Complete();
} …
Run Code Online (Sandbox Code Playgroud)

c# win-universal-app windows-10-mobile

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

名为Mutex等待

因此我不能使用线程仿射锁async- 如何在运行多个进程时保护我的资源?

例如,我有两个使用以下任务的进程:

 public async Task<bool> MutexWithAsync()
 {
     using (Mutex myMutex = new Mutex(false, "My mutex Name"))
     {
         try
         {
             myMutex.WaitOne();
             await DoSomething();
             return true;
         }
         catch { return false; }
         finally { myMutex.ReleaseMutex(); }
     }
 }
Run Code Online (Sandbox Code Playgroud)

如果由Mutex保护的moethod是同步的,那么上面的代码将起作用,但async我会得到:

从不同步的代码块调用对象同步方法.

Named Mutex对异步代码没用吗?

c# multithreading asynchronous async-await

15
推荐指数
2
解决办法
8583
查看次数

有没有正确的方法来通过其路径获取文件?

我在KnownFolders.VideosLibrary中有两个同名的文件,在这种情况下,我无法通过其名称访问文件,因此它只返回第一个文件.因此有没有其他方法来获取解析文件夹中所有文件的其他文件?

// this return two files 
var files = (await KnownFolders.VideosLibrary.GetFilesAsync()).Where(x => x.Name == "test.txt").ToArray();
// with this I can get only one file
StorageFile file = await KnownFolders.VideosLibrary.GetFileAsync("test.txt");
// of course I can parse it with query, but I would like to avoid it
// StorageFile myFile = (await KnownFolders.VideosLibrary.GetFilesAsync()).FirstOrDefault(x => x.FolderRelativeId == "something");
Run Code Online (Sandbox Code Playgroud)

我知道FutureAccessList,但它最多只能容纳1000个文件,这对我来说还不够.


请求后的一些澄清:

例如,让我们考虑使用SD卡在手机上运行应用程序.我在手机内存中的视频中有一个文件名test.txt,同名文件也存在于视频文件夹中的SD卡上.

在这种情况下,当您在上面的代码中调用第一行时,您将获得两个文件,以区分它们系统提供FolderRelativeId,因此具有相同名称的文件可以存在于一个"位置"中.如果您查看每个文件夹的完整路径,可能会有C:\Viedos\test.txt第二个文件夹D:\Videos\test.txt.

现在,第一次运行的用户选择了一个带有FilePicker的文件,我记得它的路径 …

c# win-universal-app windows-10 windows-10-mobile uwp

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

MediaElement网络视频不会停止缓冲

我使用MediaElement播放网络视频.当我离开页面时,我注意到在任务管理器中我的应用程序仍在使用10%的网络并且在完成下载视频之前没有掉线.

我尝试过以下但没有运气.

    //open link;
    mediaElement.Source = welcomeVideoURL;

    //when I leave the page OnNavigatedFrom()
    mediaElement.Stop();
    mediaElement.ClearValue(MediaElement.SourceProperty);
    mediaElement.Source = null;
Run Code Online (Sandbox Code Playgroud)

还尝试将源设置为虚拟链接但仍然没有运气.

我认为打开链接作为流和使用mediaElement.SetSource()可以工作,但我没有发现任何东西......也许我没有找到正确的.

谢谢.

c# mediaelement windows-8.1 win-universal-app

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

Windows 10 UWP应用程序中的ItemsControl和ItemTemplateSelector

我很久以前做过一些WPF编程,但我只是回到xaml与UWP,但我认为这应该工作,不知道为什么.基本上我想使用ItemsControl(因为我只想列出一些数据,我不想选择)而不是ListView控件.这是我的资源:

<Page.Resources>
    <DataTemplate x:Key="SentMessageDataTemplate">
        <TextBlock Text="Sent" />
    </DataTemplate>
    <DataTemplate x:Key="ReceivedMessageDataTemplate">
        <TextBlock Text="Recieved" />
    </DataTemplate>
    <services:MessageDataTemplateSelector x:Key="MessageDataTemplateSelector" ReceivedTemplate="{StaticResource ReceivedMessageDataTemplate}" SentTemplate="{StaticResource SentMessageDataTemplate}"></services:MessageDataTemplateSelector>
</Page.Resources>
Run Code Online (Sandbox Code Playgroud)

这是我的ItemsControl:

<ItemsControl ItemsSource="{Binding Messages}" ItemTemplateSelector="{StaticResource MessageDataTemplateSelector}" />
Run Code Online (Sandbox Code Playgroud)

这是我的DataTemplateSelector:

public class MessageDataTemplateSelector : DataTemplateSelector
{
    public DataTemplate SentTemplate
    {
        get;
        set;
    }

    public DataTemplate ReceivedTemplate
    {
        get;
        set;
    }

    protected override DataTemplate SelectTemplateCore(object item)
    {
        var message = item as MessageViewModel;
        if (message == null)
        {
            return this.SentTemplate;
        }

        return message.Sent ? this.SentTemplate : this.ReceivedTemplate;
    }
}
Run Code Online (Sandbox Code Playgroud)

它不是显示我的任何模板,而是显示我的ViewModel类型名称(所以基本上是ToString).

但是,如果我将它从ItemsControl切换到ListView,它工作正常.

有什么建议?

c# xaml win-universal-app uwp

10
推荐指数
2
解决办法
6421
查看次数

在异步任务和UI线程中引发PropertyChanged

在许多博客,教程和MSDN中,我可以读到从非UI线程访问UI元素是不可能的 - 好吧,我会得到一个未经授权的例外.为了测试它,我写了一个非常简单的例子:

// simple text to which TextBlock.Text is bound
private string sample = "Starting text";
public string Sample
{
    get { return sample; }
    set { sample = value; RaiseProperty("Sample"); }
}

private async void firstButton_Click(object sender, RoutedEventArgs e)
{
    await Job(); // asynchronous heavy job
    commands.Add("Element"); // back on UI thread so this should be ok?
}

private async Task Job()
{
    // I'm not on UI Thread ?
    await Task.Delay(2000); // some other job
    Sample = …
Run Code Online (Sandbox Code Playgroud)

c# multithreading asynchronous async-await

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