While I was working on some code today and found that some NuGet packages where out of date. So I went to update tab in Manage NuGet packages window and updated all of them. MySql.Data package (not important which package, just an example) was also updated in that from version 6.7.8 to current / latest (6.9.6). I tried to run the application to test the updates made in referring packages. I encountered following error: TypeInitializationException was unhandled An unhandled exception of type 'System.TypeInitializationException' occurred in Unknown Module. Additional information: The type initializer for '[Application Name]' threw an exception. Looking at this exception, it doesn't seems to be obvious what is going wrong here. There isn't even option for "View details". Many of you may get stuck on this and spent hours before you figure out that the AssemblyBinding.dependentAssembly.bindingRedirect are » Read more

 Jsinh        

Apple MacOS has beautiful rounded corner scrollbar and add to the UI experience you have while working on a MacOS machine. You can easily have similar scrollbar style for your WPF application to boost up your application's UI experience. If you wish to apply this scrollbar style application wide then you should follow below steps. Step: Create a new resource dictionary (skip creating if you already have one) file and add the following code to it. <Style x:Key="ScrollBarTrackThumb" TargetType="{x:Type Thumb}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Thumb}"> <Grid x:Name="Grid"> <Rectangle HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" Fill="Transparent" /> <Border x:Name="CornerScrollBarRectangle" CornerRadius=" » Read more

 Jsinh        

WPF Application developers would be experiencing or would have observed that after updating MVVMLight Toolkit package to Version 5.0.0 or 5.0.1, RelayCommand - CanExecute() mechanism is not working anymore. This issue is been already reported by MVVMLight user on codeplex as Issue# 7659. As explained by Laurent: WPF is the only XAML framework that uses the CommandManager to automagically raise the CanExecuteChanged event on ICommands. Unfortunately, there is no CommandManager in PCL (portable class library). CanExecute() is an input parameter of type action, it can be a method that returns bool based on which binding updates to allow or block command execution. This is to be passed when instantiating RelayCommand property that will bind with your control's Command property and fire the default event based on user action. A hot fix is released for above mentioned issue as Version 5.0.2 and now available on » Read more

 Jsinh        

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 » Read more

 Jsinh        

Sharing small stuffs I figure out while working with WPF !! Originally when you select any item in a ListBox control in WPF, you will observe that the background color of item turns LightBlue (if not using some kind of theming mechanism). Also when the ListBox control is not in focus or active i.e. some other control is in focus, the background color of selected item in ListBox will turn light grey (very light indeed). It would look something like this: Code snippet to apply in style / resource of the ListBox control to change the background color of the selected item when in focus or active and not in focus or inactive: <ListBox> <ListBox.Resources> <Style TargetType="{x:Type ListBoxItem}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ListBoxItem}"> <Border » Read more

 Jsinh