本文介绍了WinRT StorageFile DisplayName 奇怪的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Windows 8.1 上的 Windows 8 应用程序中,我使用 StorageFile 的 DisplayName 属性来获取友好"文件名.

In a Windows 8 app on Windows 8.1 I use the DisplayName property of StorageFile to get a 'friendly' file name.

在大多数情况下,结果是不带扩展名的文件名,但有时结果是扩展名的文件名.当我创建一个新文件夹并立即在其中创建一个文件时,似乎会发生第二种情况.

In the majority of the cases the result is the name of the file without the extension but sometimes the result is the name of the file with the extension. This second case seems to happen when I create a new folder and immediately create a file in it.

有人知道这种行为是否有一致的规则吗?

Does anyone know if there is a consistent rule for this behavior?

谢谢!

推荐答案

很奇怪,但是您可以创建扩展方法,结果将是此文件的友好名称.

It is a strange but You can create extension method which the result would be frienldy name of this file.

我是这样写的:

public static class StorageFileExtensions
{
    public static string ToFrienldyName(this StorageFile file) {
        return file.DisplayName.Replace("." + file.FileType, string.Empty);
    }
}

这篇关于WinRT StorageFile DisplayName 奇怪的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 21:21
查看更多