Shout out: WPF programmer, someday you will be asked to work on a feature where you need to show live preview of a attached USB camera (webcam) and on click of button you need to capture a picture and save or display in some image control. Pretty simple right? Well actually not, ok partially. Fine its pretty simple. Let me walk you through it and save you some time. People who wants to jump right into the code refer / download attached sample at the end of this article. Best of luck !! How to preview webcam (camera) video and take snapshot with WPF using AForge and MVVM. Step: Create a new WPF project or use your ongoing / existing WPF project, whatever you fancy. Step: Add reference to AForge NuGet package that will do the "talking to the webcam" stuffs for us. AForge.Controls AForge.Video.DirectShow By adding this two packages » Read more

 Jsinh        

One interesting feature of delegates in C# is that it provide ways to attach / detach more than one methods that has method signature similar to the delegate declared and combine them together. This combining or attaching / detaching of methods to a delegate is called Multicasting. Behind the scenes: This multicasting is possible because delegates inherit from System.MulticastDelegate which in turn inherits from System.Delegate, which inherits from Object class. How to multicast: Multicasting can be done using += and / or -= operator. Here is an example that demonstrate use of += and -= to multicast delegates. private delegate void Greetings(); static void Main(string[] args) { SayHello(); Console.ReadLine(); } public static void SayHelloToScott() { Console.WriteLine("Hi Mr. Delegate, from Scott"); } public static void SayHelloToAlex() { Console.WriteLine("How about a coffee? from Alex"); } public static void SayHelloToJasmine() { Console.WriteLine("Hi delegates, from Jasmine"); } public static void SayHelloToJsinh() { Console.WriteLine("Delegates aahaa, from Jsinh" » Read more

 Jsinh        

In case you are serializing your models to generate XML content, you will often encounter empty nodes and elements in the XML which appears when the entity property is not filled or the list is empty. Lets take an example of Employee model class as below: using System.Collections.Generic; using System.Xml.Serialization; public class Employee { public Employee() { this.Skills = new List&lt;string&gt;(); } [XmlElement("FirstName")] public string FirstName { get; set; } [XmlElement("LastName")] public string LastName { get; set; } [XmlArray("Skills")] [XmlArrayItem("Skill")] public List<string> Skills { get; set; } } When you generate XML for the above model by assigning FirstName and LastName only keeping Skills empty: var employeeDetail = new Employee() { FirstName = "Mister", LastName = "XYZ" }; var employeeDetailXml = SerializeXml(employeeDetail); you will get XML content something like this: <?xml version="1.0" encoding="utf-16"?> <Employee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns: » Read more

 Jsinh