Showing posts with label WPF. Show all posts
Showing posts with label WPF. Show all posts

Tuesday, July 9, 2013

Advanced Usage of Grouping in CollectionView with ItemsPresenter

CollectionView is an object that we generally use while dealing with a collection in WPF. It is an object structure that supports a collection as well some of the inherent features which a user might always need while dealing with a collection. Some of the features like Sorting, Grouping, Filtering are automatically implemented in a CollectionView.  I have written one article on how to deal with CollectionView way back in Aug 2010 which explains almost everything you need to do while dealing with collection in WPF. But it does not give the entire story.

Controls that can show a Collection in WPF is somehow derived from ItemsPresenter. The ItemsPresenter has a property called ItemsSource which takes an object of ICollectionView, and hence it is one of the important interfaces considered so far.

There are some advanced scenarios where the general Grouping or sorting does not makes sense. Here in this article I am going to deal with such advanced scenarios which might be worth mentioning.

Sunday, April 21, 2013

.NET Book : Visual Studio 2012 and .NET 4.5 Expert Development Cookbook (Must Read)

Friends,

It is my great honor to tell you that my book has finally been released this week. If you have ever liked any of my blogs or internals, you would like this book for sure. There are lot of things to learn from the book and I can assure you that you wont be upset with this book if you buy it.

The "Visual Studio 2012 and .NET 4.5 Expert Development Cookbook" is a book that guides you through steps to ensure you enrich the best experience with the latest technology in the best amount of time possible. The book focusses to give you under the hood expertise in .NET technologies it tends to cover and adapts you the best to face common problems of these technologies. The book is divided in forms of recipes. Each of these recipes gives you clear insight of the problem and step by step process to solve the issue practically. It also addresses the advanced features associated with each of those recipes that gives you additional advantage on getting precise knowledge about the problem and its associated issues.

What you will learn from this book



  • Basic usage of Visual Studio 2012 IDE and its various components and better utilization of the tool while writing code
  • Understand memory management techniques to build better applications
  • Understand the .NET infrastructure with in-depth analysis of its internals
  • Architect solutions that leverage the full power of .NET language gems, understanding when to use what
  • Implement multithreaded / asynchronous applications using recent updates on .NET 4.5 and compare the past approaches
  • Create secure ASP.NET web based applications in .NET 4.5 with use of JQuery and HTML5 for rapid application development
  • Architect advanced .NET client applications using MVVM with WPF 4.5
  • Understand touch sensitive devices and leverage skills to develop multi-touch applications inside Windows 8

Sunday, February 17, 2013

A new book on Kinect by Abhijit Jana - A must read

Kinect is one of the revolutionary device that were introduced lately in Microsoft ecosystem. The use of Kinect devices has increased in great extend in recent times and people are using it more and more in their day to day life. The use of Kinect is not only limited only with the gaming world, but its use is now widely spread over commercial applications too. Microsoft has released the Kinect SDK that can interact with the hardware and program on them. It is a kind of Fun working with Kinect and also writing small applications for it.

Recently I have read a book on "Kinect for Windows SDK Programming Guide" by Abhijit Jana. It is a book with great details about Kinect SDK and the Hardware. I enjoyed reading this book and thought of sharing my experiences with you such that if you are new in Kinect and want to write code on it, you might find this review helpful.

Thursday, August 23, 2012

NotifyIcon with WPF applications

NotifyIcon is an utility form System.Windows.Forms which can be used by any application to invoke the default notification from the system tray. As per my latest requirement, I have to create an application that runs on system tray and occationally shows notification using the system tray default notifications. While working with it, I have wasted a considerable amount of time, and thought it would be worth mentioning the same in a blog.

Monday, October 31, 2011

Layout adjustments Snapping and OrientationChanges in Metro Applications

If you have read my first article on Windows 8 metro styled application, you might already know about the working principle of it. I have talked about the capabilities for an application and settings which end user can configure for an application. In this post I will take a look at the basic layout structure that one needs to follow while creating an application in WinRT Metro styles so that it is best suited to perform well.

Layout is the most important part of any application. The best design for an application gets more credit and love from the users than applications that are designed bad. Metro style applications runs in full screen. Your application does not include a  Title Bar, status bar or anything. Microsoft gave us some of the basic layout guidelines that one needs to follow. Lets talk about them here to make you understand how you should layout your application in Metro Applications to utilize maximum flexibility of it.

Sunday, October 30, 2011

Understanding basic WinRT Metro Applications and Application Capabilities

Just about a month ago, WinRT was introduced with all new style of application development that can work better with Multi Touch Enabled devices. We call it as Metro Applications. In this post, I will discuss how to develop your first metro applications and how to work with its layout changes.

How to Start

Before we start talking directly about Metro Style application, let us see how to install it first. I refer to use OracleVM which you can find for free from this link, and install.  This will install a Virtual Machine in which you can install the Developer Preview of Windows 8.

Monday, September 12, 2011

Writing a Custom ConfigurationSection to handle a Collection

Configuration is one of the major thing that you need to keep in mind while building any application. Either its an Windows Forms application or a Web site, configuration file is always needed. We write all the configuration that are needed to be changed after it is being deployed in confugration files. It is an XML File which lists all the configuration blocks itself and also allows you to define your own custom configuration sections yourself. Today I am building my own custom configuration section and show how easily you can build yourself.

While dealing with Configurations, there are two things that you need to address

  1. ConfigurationSection
  2. ConfigurationElement
  3. ConfigurationElementCollection

For most of the simple configurations, it is pretty much common to use these two classes, but when you need more complex configuration block, like appsettings which actually puts a Collection of ConfigurationElements, you might need to use ConfigurationElementCollection to hold the collection of ConfigurationElement. 

Thursday, September 1, 2011

31 Tips for the month on Threading, WPF, MEF, ASP.NET


Daily .NET Tips is aiming to sharing useful coding tips and tricks for .NET Developers. This site completely design for sharing Tips and Tricks, useful Code Snippet which anyone use in daily development work and targeted anything related with .NET.   This month we have wide range of tips including Threading, MEF, WPF and MVC. In this post I am quickly listing down all the tips which are published over the month August 2011. And the most important point to mention, among those 31 tips that has been posted on DailyDotnettips this month 22 is coming from me. 

  1. Working with AggregateCatalog in MEF
  2.  Working with DirectoryCatalog in MEF
  3. Working with AssemblyCatalog in MEF
  4. Working with TypeCatalog in MEF
  5. How to use DebuggerTypeProxy while debugging your sensitive Type
  6. ASP.NET Calendar Control as Outlook Calendar
  7. Initialize assemblies using PreApplicationStartMethod for ASP.NET 4.0 Application
  8. Async Lambda Expression
  9. Playing with ASP.NET List Controls using jQuery
  10. How to allow user to input html in ASP.NET MVC?
  11. Using Mutex to avoid deadlocks
  12. Writing inline Code in WPF
  13. What is SynchronizationContext all about
  14. ThreadLocal storage in .NET
  15. Barrier in .NET 4.0
  16. Use of Interlocked in Race Condition
  17. Call ASP.NET Page Methods using your own AJAX
  18. Use of SpinLock for ThreadLocking
  19. Using ReaderWriterLock over Monitor for Thread Locking
  20. What is the use of IsBackground property of Thread?
  21. Enable Address Level Debugging in Visual Studio
  22. Get List of all Control Types in WPF
  23. How to apply simple faded transparent effects on WPF controls ?
  24.  Use Visual Studio Server Explorer to Add New or Existing SQL Server CE Database
  25. Co-Ordinated Thread Shutdown with and without using CancellationTokenSource
  26. Generate thousand of request
  27. Writing a Stretchable ContentControl in WPF
  28. How to Retrieve WPF Visual Tree Programmatically ?
  29. What is Visual Tree and Logical Tree in WPF?
  30.  Dealing with HWND in WPF
  31. Hosting a WPF control inside a Windows Form
To get regular updates visit http://dailydotnettips.com and follow @dailydotnettips at Twitter.

I hope you would like the posts. Stay tune for more. 

Monday, August 15, 2011

.NET Tips : List of my short tips

Hi Friends,

As I have already told you that I have been publishing short tips in DailyDotnetTips regularly, it is time to share the links with you to keep you updated. Please read these short tips from me and give your feedback.


  1. Using ReaderWriterLock over Monitor for Thread Locking
  2. What is the use of IsBackground property of Thread?
  3. Co-Ordinated Thread Shutdown with and without using CancellationTokenSource
  4. Writing a Stretchable ContentControl in WPF
  5. What is Visual Tree and Logical Tree in WPF?
  6. Dealing with HWND in WPF
  7. Hosting a WPF control inside a Windows Form
  8. Accessing local assemblies in XAML
  9. Difference between a UserControl and a CustomControl
  10. Hosting a Windows Forms control inside a WPF
  11. Use x:Shared to write your FrameworkElements directly as Resource
  12. Use BitmapScalingMode to ensure your rendering of Image is perfect
  13. Object hierarchy of NULL
  14. Lazy Initializer to defer expensive Object creation in .NET 4.0
  15. Working with Co-Variance and Contra-Variance in .NET 4.0
  16. Using Complex Numbers in .NET 4.0
  17. Working with BigInteger in .NET 4.0
  18. Working with SortedSet in .NET 4.0
  19. Common Table Expressions in SQL Server
  20. Compiler directive #Pragma reference

So here are my last 20 short tips posted on DailyDotnetTips

I hope you will like these tips. For full list of all the tips and the latest updates, check this link

Happy Coding. 

Thanks. 

Sunday, July 31, 2011

Internals of Dependency Property in WPF

WPF introduces new property system to us. Every WPF objects that is inherited from DependencyObject inherently supports Dependency property containers within it. That means you can define your own dependency property in your code which can take part in some of the interesting features of WPF like Binding, Styles, Triggers, Animation, Property Inheritence etc. Today I will concentrate on how Dependency Property system is actually built and what are the benefits we get instead of using CLR property system.

Note : If you are really new in WPF and don't know about Dependency Property, it would be nice to read my post on Dependency Property or you can also try WPF Tutorial series to start on.



So lets start on using the most basic code of creating your own Dependency Property.

Sunday, July 24, 2011

Writing a Reusable Custom Control in WPF

In my previous post, I have already defined how you can inherit from an existing control and define your own reusable chunk. The reusable XAML code that I have defined there is actually a composition of one of more existing elements in a common design surface. But sometimes you must define  a new behaviour for your reusable component which does not belong to any of the already existing behaviors. Custom controls can help you in this. You can define a new behaviour for your Custom control which can have a default look and feel defined for it, and obviously which can be changed using Template for the user who is using the control. In this post I am going to provide you step by step approach on defining a Custom Control for your application.

Note: If you are really new to WPF, please read my WPF Tutorial before going further. 

Steps to Create a new Custom Control

Creating a custom control is very simple. Just in your project right click and add a new Item. In the dialog box that appears, choose Custom Control template and Name it. I call it here as SimpleControl.


Once you have added the control, it adds up a new class to your project which inherits from Control. The Template also provides you with some initial help to define your own control. Lets remove all the comments for now and start building a control.

Download Sample Code


Saturday, July 23, 2011

Writing a Reusable WPF Control with Design Support

Code reusablity is one of the major concern to many of us. When dealing with large projects, modularizing your project is one of the primary thing that you should look for. I have talked about many of the approaches that you can use to deal with modularizing your code, eg, Prism. In this post our intent is not to talk hard on some pattern, rather I will discuss how your WPF application supports code reusability. There are a number of approaches that WPF supports to deal with reusable component. We can use Resources to define a Resource or even use CodeBehind to write our reusable component or even load the XAML from a file using XAML Loader. Each of the approaches has its own pros and cons. Today I will show you another cool technique to write a reusable XAML for your project which will allow you to easily use Visual Studio design surface to design the component.

Note : It is a very basic article, if you want to know about details on WPF, please read my tutorial on it.

Steps to Create your Reusable Component


Lets create a series of steps to create a reusable component for your application to make it easier for you to write one yourself.


Sunday, June 5, 2011

Working With Prism 4.0 (Hello World Sample with MVVM)

Modularity is one of the primary concern when working with a big projects. Most of us think of how we can implement our application that could be reusable across more than one applications. Patterns and Practices Team puts forward the notion of modularity with the help of Unity and Prism which most importantly focus on WPF and Silverlight applications. Being a WPF developer, it would be nice to take this apart and explain you a bit of how you can implement your application using Prism.

Before you begin, I must tell you, this is the most basic article that guides you step by step how you can write your first Prism based application and what are the advantages of building such kind of application. I will take this further in my next posts to make more concrete samples. So if you know the basics of how you can work with Prism, I would recommend you to read my next posts.

Also I assume you have some knowledge of Unity, WPF and MVVM to get you through with Prism.

Where do I find Prism? 

Prism is a framework introduced by Patterns and Practices Team which is available from here. After you install your bits, you will get a folder named Prism on your local drive. After you are done, lets start coding.

Thursday, April 14, 2011

Silverlight 5 Beta - Lets deal with its features

In MIX 2011, we can see our very own silverlight new version called Silverlight 5 beta is released. Yes, if you are looking for it, its time to download the beta and try them out. The major goal of Silverlight 5 is to move the silverlight development more towards the WPF and hence releasing some of the benefits that you already enjoy being a WPF developer is now available to silverlight. In this post lets talk about the features that were introduced with Silverlight one by one.

To install Silverlight 5

To try the features, you first need to download the Beta. Lets follow the steps to install silverlight in your machine.

  1. You first need to download Visual Studio 2010 (SP 1) if you didn't have done that already. 
  2. After you install Visual studio update you need Silverlight tools for Visual Studio
  3. Optionally you can also try Silverlight help tools to get started.
Now after you are done with this, lets talk about few basic features introduced in Silverlight 5.

Silverlight 5 Features 

You should notice that there are few major benefits that are not present yet with Silverlight 5 beta, to name a few :
  • Our old requirement to support 64 Bit is not present
  • You still cannot launch external applications (using PInvoke) with elevated trust level
  • DataContextChanged is still not present.
  • Vector Printing

Monday, April 4, 2011

Internals of LINQ

If you remember my post on Annonymous Types, I have already stated that there is no concept of annonymous types in MSIL. Every generated type will be mapped to a concrete type produced by C# compiler during the runtime. In this post, I am going to cover few basics of LINQ, and how it is been maintained in IL. If you are very new to Linq, it is recommended to learn the basic usage of it first. You can read my article on Linq Basics, to know more about it.

LINQ means Language Integrated Query is one of the major step forward to .NET framework to support queries to work on objects. LINQ allows you to write custom query statements on .NET objects or more specifically any IEnumerables to filter or fetch data from it.

In this post, I am not covering the basics as I have already discussed it in a separate article. Lets start with internals.

Tuesday, March 22, 2011

Issue with RadioButtons and Binding for MVVM

Well, if you are working with WPF or silverlight, and in VS 2008, I think you would have definitely found this issue or will find it sooner.

Most of us when dealing with WPF applications must have been using MVVM pattern where you want to completely separate the presentation layer into a View Models. Well, it would be hard to create MVP or MVVM pattern yourself in other applications, but WPF has inbuilt support of MVVM with Command interfaces and Binding.  Binding is the concept which lets you to update the control whenever the underlying data object is modified and vice versa.

Most of the controls works great with Binding and hence can easily be used with MVVM pattern, but RadioButton has serious issue with it. In this post I will describe the problem with Radios and define some of the ways to solve it.

Sunday, March 13, 2011

Deal with Performance in WPF applications

Hi friends,

WPF is one of the major changes to the desktop applications in recent times. Most of us is using it in your day to day life programming. Some use for normal desktop or windows based applications while others write programs that run in browsers as Sandboxed application. The major investments of Microsoft on making silverlight to work out of browser enhanced the usage of WPF in a larger extent. But as for any other application, performance is the major issue for your application. Its not how well you structured your application, or how loose couple your UI with other layers, it is often a requirement for any software on how it acts in stressed situations.

One of such performance hits that might appear for your WPF application is over utilization of CPU. In this post, I will cover some of the general performance hiccups with WPF which you might consider unnecessary for your application or may be you want just to identify them for your application. Lets put few of the performance improvement tips for you in this post :


Friday, March 11, 2011

RegisterName for StoryBoards in WPF (NameScopes)

Guys,

Have you ever tried to use your Code-Behind extensively in WPF rather than using XAML to design your objects? Certainly there is no way you would like to do this when you have an option to avoid, but sometimes it is almost necessary to do such code.

You may argue, even you are smart enough to deal such situation yourself using DataTemplates and Resources and make your application truly data driven. Yes it is possible, MVVM addresses such situation, but as I must say it is not always a silver bullet to address situations like this, it is more likely you might device your work more in code. Yes, even if you ask me, I am also less comfortable in Code to do the same design as I am in XAML.

Today, one of my pal asked me the code which would add some Random Ellipse in a black Canvas and these points will also move in the screen using a DoubleAnimation. As per my initial thought is concerned, the code seemed to me good. The code looks like :

Monday, March 7, 2011

All about .NET Timers - A Comparison

Threads and Timers are the most common things that you need for your application. Any work that needs to be done in background without intervening the work that is running in the foreground needed to be done using a Thread. We create Threads to delegate a long running process in background so that the UI remains unblocked. Timers on the other hand is a special module which runs after a certain interval of time in background. So you would think Timers will also create a new Thread in background and runs the module associated with it after a certain time. This is not always true.
In this post, I will compare most of the timers available with .NET right now, and later on discuss about DispatcherTimer in WPF.

Difference between Concurrency and Asynchrony?

Now if you look back when Microsoft introduced async CTP in PDC 2010,  or my own article on Async, it is clearly stated that Asynchrony and Concurrency are two different concepts. Asynchrony means running a job without blocking the Thread where it is working at. Concurrency is actually a special kind of asynchrony where it is achieved by creating a new Thread. Hence you can say, all sorts of concurrency is asynchrony while all asynchrony is not concurrency. You can have asynchrony without concurrency and it is really worth doing that, as you all know it is not good to put every work in Separate thread. ThreadPools could somewhat help by allowing you to manage threads but still Threads are for long running background processes, so beware to use it only when you absolutely require it.

Going ahead with this thought, lets compare the existing Timers.There are a number of Timers available with .NET before. Many of us might not know what is the basic difference between them. Lets put a comparative analysis on them one by one.

Saturday, February 5, 2011

Get Reflected use TypeDescriptor

Hi there. Reflection is one of the major library that runs over the CLR which lets you get information about a CLR type or an object during runtime. A large number of application which is built today is taking advantage of Reflection to make their 3rd party codes plugin to their application dynamically. The Reflection lets you explain objects and its behavior dynamically and without any static binding available to any of those objects.

 But if you just need to get information about the objects at runtime, Reflection APIs needs a hands experience and a lot of heck to do a job. A number of classes that is built over the Reflection APIs can be used to make your life easier while you code. One of the few libraries that are available with you that I must address is the classes within ComponentModel namespace. In this post I will give you a sample demonstration of how you could use Descriptor types to get information about Properties, Attributes, Events etc without invoking a single line of Reflection calls. I hope you could use the code later while building your library.


Author's new book

Abhishek authored one of the best selling book of .NET. It covers ASP.NET, WPF, Windows 8, Threading, Memory Management, Internals, Visual Studio, HTML5, JQuery and many more...
Grab it now !!!