Wpf rewrite

Merge WPF rewrite in master branch.