win8初级知识

1、Win8 Metro下的MessageBox
  1. private async void No_But_Click(object sender, RoutedEventArgs e)
  2.         {
  3.             MessageDialog msg = new MessageDialog("确定退出应用吗?", "提示");
  4.             msg.Commands.Add(new UICommand("是", new UICommandInvokedHandler(this.CommandInvokedHandler)));
  5.             msg.Commands.Add(new UICommand("否", new UICommandInvokedHandler(this.CommandInvokedHandler)));
  6.             await msg.ShowAsync();
  7.         }
  8.         private void CommandInvokedHandler(IUICommand command)
  9.         {                  
  10.             this.Dispatcher.Invoke(Windows.UI.Core.CoreDispatcherPriority.Normal, (s, a) =>
  11.             {
  12.                 UserName_TB.Text = command.Label;
  13.             }, this, null);
  14.         }
复制代码
2、消除AppBar阻挡
  1. <AppBar Name="pb"   VerticalAlignment="Bottom" HorizontalContentAlignment="Stretch" Height="88" VerticalContentAlignment="Stretch" Background="#E5058AE6" Visibility="Collapsed">
  2.             <Grid>
  3.                 <Grid.ColumnDefinitions>
  4.                     <ColumnDefinition/>
  5.                     <ColumnDefinition/>
  6.                 </Grid.ColumnDefinitions>
  7.                 <StackPanel Grid.Column="1" Orientation="Horizontal"/>
  8.                 <StackPanel Orientation="Horizontal"/>
  9.             </Grid>
  10.         </AppBar>
复制代码
后台代码:
  1. protected override void OnRightTapped(RightTappedRoutedEventArgs e)
  2.         {     
  3.             if (!pb.IsOpen)
  4.             {
  5.                 pb.Visibility = Visibility.Visible;
  6.             }
  7.             else
  8.             {
  9.                 pb.Visibility = Visibility.Collapsed;
  10.             }
  11.             base.OnRightTapped(e);              
  12.         }
复制代码
3、Image加载图片
  1. img.Source = new BitmapImage(new Uri( "ms-appx:/Images/a.png", UriKind.RelativeOrAbsolute));
复制代码
4、获取摄像头图片
  1. private async void Button_Click(object sender, RoutedEventArgs e)
  2.         {
  3. CameraCaptureUI camera = new CameraCaptureUI();
  4.             camera.PhotoSettings.CroppedAspectRatio = new Size(1, 1);//比例   
  5.             camera.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Png;//图片格式
  6.             // dialog.PhotoSettings.CroppedSizeInPixels = new Size(100, 150);//固定大小        
  7.             StorageFile file = await camera.CaptureFileAsync(CameraCaptureUIMode.Photo);
  8.             if (file != null)
  9.             {
  10.                 BitmapImage bitmapImage = new BitmapImage();
  11.                 using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
  12.                 {
  13.                     bitmapImage.SetSource(fileStream);
  14.                 }
  15.                 img.Source = bitmapImage;
  16.                 aaa.Content = file.Path;
  17.             }
  18. }
复制代码
5、获取摄像头视频
  1. private async void Button_Click(object sender, RoutedEventArgs e)
  2.         {
  3.             CameraCaptureUI dialog = new CameraCaptureUI();
  4.             dialog.VideoSettings.Format = CameraCaptureUIVideoFormat.Mp4;
  5.             StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Video);
  6.             if (file != null)
  7.             {              
  8.                 IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
  9.                 mediaelement.SetSource(fileStream,"video/mp4");
  10.             }
  11.         }
复制代码
6、获取摄像头视频到程序中
  1. MediaCapture mediaCaptureMgr;   
  2.         private async void Button_Click(object sender, RoutedEventArgs e)
  3.         {
  4.             mediaCaptureMgr = new MediaCapture();
  5.             await mediaCaptureMgr.InitializeAsync();
  6.             Scenario1Video.Source = mediaCaptureMgr;
  7.             await mediaCaptureMgr.StartPreviewAsync();   
  8.         }
复制代码
7、获取系统文件
  1. FileOpenPicker openPicker = new FileOpenPicker();
  2.             openPicker.ViewMode = PickerViewMode.List;//显示文件样式
  3.             openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;//图片库为查找目标路径
  4.             openPicker.FileTypeFilter.Add(".iso");         //查找文件类型
  5.             IReadOnlyList<StorageFile> files = await openPicker.PickMultipleFilesAsync();//获取文件
  6.             //显示文件
  7.             foreach (StorageFile v in files)
  8.             {
  9.                 lv.Items.Add(v.Path);
  10.             }
复制代码
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值