Alright, thanks to Milton Miranda Neto, for his code. At last i did suceed in c# using this extension. You can watch this http://youtu.be/-V0xiyQcYaM video for more help.
using System;
using System.Linq;
using System.IO;
using System.IO.IsolatedStorage;
using System.Collections.Generic;
using Microsoft.LightSwitch;
using Microsoft.LightSwitch.Framework.Client;
using Microsoft.LightSwitch.Presentation;
using Microsoft.LightSwitch.Presentation.Extensions;
using WebcamExtension.Presentation.Controls;
namespace LightSwitchApplication
{
public partial class CreateNewCustomer
{
/// <summary>
/// Initializes a new customer object and assigns it to the CustomerProperty for the screen.
/// </summary>
WebcamControl webCam;
partial void CreateNewCustomer_InitializeDataWorkspace(global::System.Collections.Generic.List<global::Microsoft.LightSwitch.IDataService> saveChangesTo)
{
// Write your code here.
this.CustomerProperty = new Customer();
}
/// <summary>
/// Closes the Create New Customer screen after saving and focuses to the originating screen.
/// </summary>
partial void CreateNewCustomer_Saved()
{
// Write your code here.
this.Close(false);
Application.Current.ShowDefaultScreen(this.CustomerProperty);
}
partial void CreateNewCustomer_Created()
{
IContentItemProxy ctl = this.FindControl("ScreenContent");
ctl.ControlAvailable += new EventHandler<ControlAvailableEventArgs>(CapturaControl);
}
private void CapturaControl(Object sender, ControlAvailableEventArgs e)
{
webCam = ((WebcamControl)e.Control);
webCam.CaptureCompleted += new WebcamControl.CaptureCompletedEventHandler(webCam_CaptureCompleted);
}
private void webCam_CaptureCompleted()
{
CustomerProperty.Picture = webCam.CapturedImage;
}
}
}
Hi,
Can you please update on how exactly should I use this control. I created a local Image type property & changed the control type to this control.
When I start the cam & click on get Image nothing happens.
Am I missing something here?
Kindly let me know if there is something that needs to be done in order to hook the image to an existing User profile.
Regards
Supreet
Hi, did you watch the video on the extension's home page? :-)
You must not replace the Image type control, leave it unchanged. Simply add a new custom control and change this to use the extension. The control returns an image that can be assigned to the Image type.
All the best.
Hi,
if I use the control within a modalwindow, and closing it without clicking [Stop] and open it again and click the [Start] I get an error saying that the webcam is being used already. how can I solve this problem?
I create the solution.
' ---------- ModalWindow webcam ----------
Private WithEvents WebCam As WebcamControl
Private Sub Funcionarios_Created()
Dim Ctrl = Me.FindControl("ScreenContent")
AddHandler Ctrl.ControlAvailable, Sub(sender As Object, e As ControlAvailableEventArgs)
Me.WebCam = CType(e.Control, WebcamControl)
End Sub
End Sub
Private Sub WebCam_CaptureCompleted() Handles WebCam.CaptureCompleted
Me.Funcionarios1.SelectedItem.Foto = Me.WebCam.CapturedImage
End Sub
Private Sub CarregarFotoDaWebCam_Execute()
Dim Ctrl = Me.FindControl("WebCamModalWindow")
AddHandler Ctrl.ControlAvailable, Sub(sender As Object, e As ControlAvailableEventArgs)
Dim Cw As ChildWindow = CType(e.Control, ChildWindow)
AddHandler Cw.Closing, Sub(sender2 As Object, e2 As EventArgs)
Me.WebCam.capSource.Stop()
End Sub
End Sub
Me.OpenModalWindow("WebCamModalWindow")
End Sub
Private Sub FotoOK_Execute()
Me.CloseModalWindow("WebCamModalWindow")
End Sub
El excelente ejemplo de Alessandro Del Sole para WebCam Extension
(http://visualstudiogallery.msdn.microsoft.com/6beb1508-e025-420b-a01c-677aad550ac6) en VB.Net, traducido por mi
a C#. Muchas Gracias Alessandro
To forgive for the translation the Englishman - translated by the web.
for WebCam Extension (http: // visualstudiogallery.msdn.microsoft.com/6beb1508-e025-420b-a01c-677aad550ac6) in VB.Net,
translated for my to C.
Thank you very much Alessandro
----------------------------------------------------------------------------------------------------------------
using System.Linq;
using System.IO;
using System.IO.IsolatedStorage;
using System.Collections.Generic;
using Microsoft.LightSwitch;
using Microsoft.LightSwitch.Framework.Client;
using Microsoft.LightSwitch.Presentation;
using Microsoft.LightSwitch.Presentation.Extensions;
using WebcamExtension.Presentation.Controls;
namespace LightSwitchApplication
{
public partial class NuevoContacto
{
private WebcamControl webCam;
partial void NuevoContacto_InitializeDataWorkspace(global::System.Collections.Generic.List<global::Microsoft.LightSwitch.IDataService> saveChangesTo)
{
this.ContactosProperty = new Contactos();
}
partial void NuevoContacto_Saved()
{
this.Close(false);
Application.Current.ShowDefaultScreen(this.ContactosProperty);
}
partial void NuevoContacto_Created()
{
var ctrl = this.FindControl("ScreenContent");
ctrl.ControlAvailable += (object sender, ControlAvailableEventArgs e) =>
{
this.webCam = (WebcamControl)e.Control;
};
}
private void webCam_CaptureCompleted()
{
this.ContactosProperty.Foto = this.webCam.CapturedImage;
}
partial void NuevoContacto_Activated()
{
webCam.CaptureCompleted += webCam_CaptureCompleted;
}
}
}