Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I was following this tutorial thing (the WPF: Webcam Control Article) on a WPF Webcam control and did the following: I took the c# code and converted it to vb.net using a code converter and entered that as my code. However, I cannot view the designer because "value does not fall withing expected range line 0 column 0". Does anyone know how to fix this? Supposedly I have two contradicting terms someplace but I am very new to this and do not recognize them. If you could help that would be fantastic!

Here is a piece of the coding:
VB
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Windows.Navigation
Imports System.Windows.Shapes
Imports Microsoft.Expression.Encoder.Devices
Imports WebcamControl
Imports System.IO
Imports System.Drawing.Imaging

Namespace WPF_Webcam
    ''' <summary>
    ''' Interaction logic for MainWindow.xaml
    ''' </summary>
    Partial Public Class MainWindow
        Inherits Window
        Private webCamCtrl As Webcam

        Public Sub New()
            InitializeComponent()

            webCamCtrl = New Webcam()

            ' Bind the Video and Audio device properties of the
            ' Webcam control to the SelectedValue property of 
            ' the necessary ComboBox.
            Dim bndg_1 As New Binding("SelectedValue")
            bndg_1.Source = VidDvcsComboBox
            webCamCtrl.SetBinding(Webcam.VideoDeviceProperty, bndg_1)
Posted
Updated 16-Nov-12 5:14am
v3
Comments
Christian Graus 16-Nov-12 10:39am    
Being 'new to this', you should learn VB.NET or C#, not play with code samples you don't understand on the net, let alone learning WPF. What line gives the error ? What does the C# code look like ?
FearfulSymmetry 16-Nov-12 10:52am    
You are right that I should learn VB.NET or C# but I have no where to learn it. No programming classes are offered at my school and I have searched the net over for help but have found no straight answers. If you know where I can go or have any sources that would help, please share. If not, here is the C# code.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Expression.Encoder.Devices;
using WebcamControl;
using System.IO;
using System.Drawing.Imaging;

namespace WPF_Webcam
{
///
/// Interaction logic for MainWindow.xaml
///

public partial class MainWindow : Window
{
private Webcam webCamCtrl;

public MainWindow()
{
InitializeComponent();

webCamCtrl = new Webcam();

// Bind the Video and Audio device properties of the
// Webcam control to the SelectedValue property of
// the necessary ComboBox.
Binding bndg_1 = new Binding("SelectedValue");
bndg_1.Source = VidDvcsComboBox;
webCamCtrl.SetBinding(Webcam.VideoDeviceProperty, bndg_1);

Binding bndg_2 = new Binding("SelectedValue");
bndg_2.Source = AudDvcsComboBox;
webCamCtrl.SetBinding(Webcam.AudioDeviceProperty, bndg_2);

// Create directory for saving video files.
string vidPath = @"C:\VideoClips";

if (Directory.Exists(vidPath) == false)
{
Directory.CreateDirectory(vidPath);
}

// Create directory for saving image files.
string imgPath = @"C:\WebcamSnapshots";

if (Directory.Exists(imgPath) == false)
{
Directory.CreateDirectory(imgPath);
}

// Set some properties of the Webcam control
webCamCtrl.VideoDirectory = vidPath;
webCamCtrl.VidFormat = VideoFormat.wmv;

webCamCtrl.ImageDirectory = imgPath;
webCamCtrl.PictureFormat = ImageFormat.Jpeg;

// Set the Webcam control as the ContentControl's content.
ContentControl1.Content = webCamCtrl;

// Find a/v devices connected to the machine.
FindDevices();

VidDvcsComboBox.SelectedIndex = 0;
AudDvcsComboBox.SelectedIndex = 0;
}

private void FindDevices()
{
var vidDevices = EncoderDevices.FindDevices(EncoderDeviceType.Video);
var audDevices = EncoderDevices.FindDevices(EncoderDeviceType.Audio);

foreach (EncoderDevice dvc in vidDevices)
{
VidDvcsComboBox.Items.Add(dvc.Name);
}

foreach (EncoderDevice dvc in audDevices)
{
AudDvcsComboBox.Items.Add(dvc.Name);
}

}

private void StartButton_Click(object sender, RoutedEventArgs e)
{
try
{
// Display webcam video on control.
webCamCtrl.StartCapture();
}
catch (Microsoft.Expression.Encoder.SystemErrorException ex)
{
MessageBox.Show("Device is in use by another application");
}
}

private void EndButton_Click(object sender, RoutedEventArgs e)
{
// Stop the display of webcam video.
webCamCtrl.StopCapture();
}

private void RecordButton_Click(object sender, RoutedEventArgs e)
{
// Start recording of webcam video to harddisk.
webCamCtrl.StartRecording();
}

private void StopRecord
Christian Graus 16-Nov-12 10:57am    
And yet here you are on a website full of programming articles and people willing to help. You should use these resources, but set yourself sensible goals. I think everyone should start by writing a basic calculator that works on the console, for example.
FearfulSymmetry 16-Nov-12 11:09am    
Ok! I will try writing one. Thanks for the advice.
Christian Graus 16-Nov-12 11:12am    
Don't forget, we will love to help if you have a problem and ask questions that show you're trying to do it yourself and just need help. A forum like this is really an awesome chance to learn, if you use it right.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900