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 creating this » 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="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" Margin="0,1,0,1" Background="{TemplateBinding Background}" /> </Grid> <ControlTemplate. » 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 two packages » 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 x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush} » Read more

 Jsinh        

Application speaks your business. The application works fine – check, it does not crash while you pop some popcorns – check, it does show correct results and data – check, it cannot get anymore faster than this – check, does not keep showing “loading, please wait” message for next 100 years – check. Phew, finally your application is all good to go. But are we not forgetting something? Presentation or the visuals plays an equally important role in success of any business solution / application. Condition – it is not some high end, supa dupa background processing application. This presentation part can be different for each and every solutions coded out there. They may have glassy sprites and rich menus, some might be theme based. Some impress well using javascript or animation and so on. One of the Titanic times solution for desktop application to improve presentation quality is start-up splash screen. Application splash screen can be » Read more

 Jsinh        

Lately Microsoft have been using some of the well known design patterns to ease and furnish work of a programmer who choose to bang keyboards using .NET. One good example is WPF commands. Microsoft at MSDN on Commanding: Commanding is an input mechanism in Windows Presentation Foundation (WPF) which provides input handling at a more semantic level than device input. It resembles and is inspired by the famous Command Design Pattern with Microsoft flavors added to it. This Routed command system as named by Microsoft is a modified version of the original command design pattern with routing capabilities. It is used to send command and / or behavioral notifications from UI controls. They are analogous to the Routed event system in WPF. The routed command system in WPF has two types of commands: Routed Commands Routed UI Commands It becomes clear from the name itself that the first is used to » Read more

 Jsinh