Click here to Skip to main content
12,749,754 members (36,206 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET Webcam
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 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:
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()

            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 16-Nov-12 5:33am
Updated 16-Nov-12 6:14am
Tim Corey116.2K
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
/// <summary>
/// Interaction logic for MainWindow.xaml
public partial class MainWindow : Window
private Webcam webCamCtrl;

public MainWindow()

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)

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

if (Directory.Exists(imgPath) == false)

// 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.

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)

foreach (EncoderDevice dvc in audDevices)


private void StartButton_Click(object sender, RoutedEventArgs e)
// Display webcam video on control.
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.

private void RecordButton_Click(object sender, RoutedEventArgs e)
// Start recording of webcam video to harddisk.

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.
Sergey Alexandrovich Kryukov 16-Nov-12 12:03pm
Who told you that the technology and even science is learned in the class? Most important thing in college or university is the examination, because many students cannot tell the difference between their real knowledge and illusory knowledge, and because, without examinations, there is no a reference point for comparing the skills. Everything else can be learned by books and by practicing, and these days also with Internet. As to examinations, you can instead have your colleagues review your work...

I can tell you more: nearly all decent software developers I knew are self-taught. They learned mathematics and other fundamental things in universities, but computer science and practice mostly by themselves.

Key thing here is deep interest, hard requirements you apply to yourself, hard work and the habit to think in depth...

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170215.1 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100