zoukankan      html  css  js  c++  java
  • <metro>读取文件名

    首先,我们打开VS2012,选择模板 Blank App,填好名字点击进入。在MainPage.xaml中选择一个Button和TextBlock 控件。可以在button中选择事件Click。在xaml中代码如下:

     <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
            <Button x:Name="File" Content="Button" HorizontalAlignment="Left" Height="60" Margin="284,116,0,0" VerticalAlignment="Top" Width="203" Click="File_Click"/>
            <TextBlock x:Name="ftxt" HorizontalAlignment="Left" Margin="284,207,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Height="179" Width="402"/>
        </Grid>

    其次,在事件中,用FileOpenPicker类new一个,在一步步用FileTypeFilter选择文件类型。接着,用 StorageFile获取文件,并将名字读到TextBlock中。

    最后,按F5运行。我们就可以选择定好的文件的类型,读出文件名。在事件中代码如下:  

     private async void File_Click(object sender, RoutedEventArgs e)
            {
                FileOpenPicker openPicker = new FileOpenPicker();
                openPicker.ViewMode = PickerViewMode.Thumbnail;
                openPicker.SuggestedStartLocation = PickerLocationId.Desktop;
                openPicker.FileTypeFilter.Add(".txt");
                openPicker.FileTypeFilter.Add(".dps");
                openPicker.FileTypeFilter.Add(".xlsx");
                openPicker.FileTypeFilter.Add(".docx");
    
                StorageFile file = await openPicker.PickSingleFileAsync();
                if (file != null)
                {
                    ftxt.Text = "Picked file: " + file.Name;
                }
                else
                {
                    ftxt.Text = "Operation cancelled.";
                }
            }

            

  • 相关阅读:
    一份面试题+整理的答案
    java获取本机IPV4地址,非127.0.0.1
    List去重
    禁止iframe页面时产生历史记录
    js打开新窗口并且不被拦截
    ifream 跨域实现高度自适应
    css版tooltip
    jQuery遮罩插件 jQuery.blockUI.js
    SpringMVC 传递相同名称的参数
    SpringMVC接收List型参数
  • 原文地址:https://www.cnblogs.com/virgil/p/2747705.html
Copyright © 2011-2022 走看看