Win8开发技术点积累(一)
VS11下载地址:
http://www.microsoft.com/click/services/Redirect2.ashx?CR_CC=2000981141 Win8 Metro下的MessageBox
private async void No_But_Click(object sender, RoutedEventArgs e) { MessageDialog msg = new MessageDialog("你真的要确定退出你的应用吗?", "桂素伟提示"); msg.Commands.Add(new UICommand("是", new UICommandInvokedHandler(this.CommandInvokedHandler))); msg.Commands.Add(new UICommand("否", new UICommandInvokedHandler(this.CommandInvokedHandler))); await msg.ShowAsync(); } private void CommandInvokedHandler(IUICommand command) { this.Dispatcher.Invoke(Windows.UI.Core.CoreDispatcherPriority.Normal, (s, a) => { UserName_TB.Text = command.Label; }, this, null); }2 消除AppBar阻挡<AppBar Name="pb" VerticalAlignment="Bottom"HorizontalContentAlignment="Stretch" Height="88" VerticalContentAlignment="Stretch" Background="#E5058AE6" Visibility="Collapsed"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition/> </Grid.ColumnDefinitions> <StackPanel Grid.Column="1" Orientation="Horizontal"/> <StackPanel Orientation="Horizontal"/> </Grid> </AppBar>后台代码:protected override void OnRightTapped(RightTappedRoutedEventArgs e) { if (!pb.IsOpen) { pb.Visibility = Visibility.Visible; } else { pb.Visibility = Visibility.Collapsed; } base.OnRightTapped(e); }3 Image加载图片img.Source=newBitmapImage(newUri("ms-appx:/Images/a.png",UriKind.RelativeOrAbsolute));4 获取摄像头图片privateasyncvoidButton_Click_1(objectsender,RoutedEventArgse){CameraCaptureUIcamera=newCameraCaptureUI();
camera.PhotoSettings.CroppedAspectRatio=newSize(1,1);//比例
camera.PhotoSettings.Format=CameraCaptureUIPhotoFormat.Png;//图片格式
//dialog.PhotoSettings.CroppedSizeInPixels=newSize(100,150);//固定大小
StorageFilefile=awaitcamera.CaptureFileAsync(CameraCaptureUIMode.Photo);
if(file!=null)
{
BitmapImagebitmapImage=newBitmapImage();
using(IRandomAccessStreamfileStream=awaitfile.OpenAsync(Windows.Storage.FileAccessMode.Read))
{
bitmapImage.SetSource(fileStream);
}
img.Source=bitmapImage;
aaa.Content=file.Path;
}}5 获取摄像头视频private async void Button_Click_1(object sender, RoutedEventArgs e) { CameraCaptureUI dialog = new CameraCaptureUI(); dialog.VideoSettings.Format = CameraCaptureUIVideoFormat.Mp4; StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Video); if (file != null) { IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); mediaelement.SetSource(fileStream,"video/mp4"); } }6 获取摄像头视频到程序中MediaCapturemediaCaptureMgr;
privateasyncvoidButton_Click_1(objectsender,RoutedEventArgse)
{
mediaCaptureMgr=newMediaCapture();
awaitmediaCaptureMgr.InitializeAsync();
Scenario1Video.Source=mediaCaptureMgr;
awaitmediaCaptureMgr.StartPreviewAsync();
}7 获取系统文件
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.List;//显示文件样式
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;//图片库为查找目标路径
openPicker.FileTypeFilter.Add(".iso"); //查找文件类型
IReadOnlyList<StorageFile> files = await openPicker.PickMultipleFilesAsync();//获取文件
//显示文件
foreach (StorageFile v in files)
{
lv.Items.Add(v.Path);
}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。