使用Xamarin Forms+XLabs 完成 Camara access
2016-03-10 15:45
381 查看
1. 安装nuget
Xamarin.Forms
XLabs.Forms
2. MainActivity.cs (Android)
3. ViewModel (Portable)
CamaraViewModel.cs
从这里拿的 https://github.com/XLabs/Xamarin-Forms-Labs/blob/master/Samples/XLabs.Sample/ViewModel/CameraViewModel.cs
4. View (portable)
Photo.xaml
在App.cs (portable) 初始view指向photo即可
Xamarin.Forms
XLabs.Forms
2. MainActivity.cs (Android)
public class MainActivity : XFormsApplicationDroid { /// <summary> /// Called when [create]. /// </summary> /// <param name="bundle">The bundle.</param> protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); if (!Resolver.IsSet) { this.SetIoc(); } else { var app = Resolver.Resolve<IXFormsApp>() as IXFormsApp<XFormsApplicationDroid>; if (app != null) app.AppContext = this; } Xamarin.Forms.Forms.Init(this, bundle); this.LoadApplication(new App()); } /// <summary> /// Sets the IoC. /// </summary> private void SetIoc() { var resolverContainer = new SimpleContainer(); var app = new XFormsAppDroid(); app.Init(this); resolverContainer.Register<IDevice>(t => AndroidDevice.CurrentDevice) .Register<IMediaPicker, MediaPicker>(); Resolver.SetResolver(resolverContainer.GetResolver()); } }
3. ViewModel (Portable)
CamaraViewModel.cs
从这里拿的 https://github.com/XLabs/Xamarin-Forms-Labs/blob/master/Samples/XLabs.Sample/ViewModel/CameraViewModel.cs
4. View (portable)
Photo.xaml
<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:viewModels="clr-namespace:PhotoSample.ViewModels;assembly=PhotoSample" x:Class="PhotoSample.Views.Photo"> <ContentPage.BindingContext> <viewModels:CameraViewModel /> </ContentPage.BindingContext> <StackLayout> <Button Text="Take Picture" Command="{Binding TakePictureCommand}" /> <Button Text="Select Image from Picture Library" Command="{Binding SelectPictureCommand}" /> <Button Text="Select Video from Picture Library " Command="{Binding SelectVideoCommand}" /> <Image Source="{Binding ImageSource}" VerticalOptions="CenterAndExpand" /> <Entry Text="{Binding VideoInfo}" VerticalOptions="CenterAndExpand" /> </StackLayout> </ContentPage>
在App.cs (portable) 初始view指向photo即可
MainPage = new Photo();
相关文章推荐
- iOS-UIAlertController简易封装
- python:解析XML文件后写入EXCEL(一)
- USB HID简介,开发USB设备必备
- 二分法查找的C++实现
- 特征降维 理论
- 关于catch的异常另一种用法
- Calender上下午使用
- 当数据类型为Date,不同的显示方法出现不同的格式
- Ubuntu下的交叉编译
- 设计模式学习笔记
- 贪心算法:旅行商问题(TSP)
- 寻找第k元
- mysql group by 用法解析(详细)
- Redis实战之Redis + Jedis
- 编译windows版的openssl
- Linux常用软件
- git忽略对已入库文件的修改
- 寻找第k元
- 多个Activity轮训切换的实现
- 贪心算法:旅行商问题(TSP)