How can I produce a “print preview” of a FlowDocument in a WPF application?

Taking the hint from the comment added to my question, I did this: private string _previewWindowXaml = @”<Window xmlns=”” xmlns:x =’’ Title=”Print Preview – @@TITLE” Height=”200″ Width=”300″ WindowStartupLocation =’CenterOwner’> <DocumentViewer Name=”dv1″/> </Window>”; internal void DoPreview(string title) { string fileName = System.IO.Path.GetRandomFileName(); FlowDocumentScrollViewer visual = (FlowDocumentScrollViewer)(_parent.FindName(“fdsv1”)); try { // write the XPS document using (XpsDocument doc … Read more

Secure Password Hashing [closed]

Salt your hash with secure random salt of at least 128bits or longer, to avoid a rainbow attack and use BCrypt, PBKDF2 or scrypt. PBKDF2 comes with NIST approval. To quote: The problem is that MD5 is fast. So are its modern competitors, like SHA1 and SHA256. Speed is a design goal of … Read more

Do I need to dispose of a Task?

While the normal rule of thumb is to always call Dispose() on all IDisposable implementations, Task and Task<T> are often one case where it’s better to let the finalizer take care of this. The reason Task implements IDisposable is mainly due to an internal WaitHandle. This is required to allow task continuations to work properly, … Read more

Does .NET have the history of time zone changes?

.NET tracks some history, but it is not always accurate. You’ve stumbled upon one of the inaccuracies. .NET imports all of it’s time zone information from Windows via the registry, as described here and here. If you look in the registry at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\Russian Standard Time\Dynamic DST you’ll find that it only tracks information … Read more

Zoom in on a web page using WebBrowser .NET control

There appears to be a solution at IE Zoom that involves overriding AttachInterfaces and DetachInterfaces in the WebBrowser to get a IWebBrowser2 interface, and then calling ExecWB with OLECMDID_OPTICAL_ZOOM. I’ve tried his sample code and it appears to work; the (abridged) relevant class looks like this: using System; using System.Windows.Forms; using System.Runtime.InteropServices; namespace ZoomBrowser { … Read more

How to improve painting performance of DataGridView?

I recently had some slowness issues with DataGridView and the solution was the following code public static void DoubleBuffered(this DataGridView dgv, bool setting) { Type dgvType = dgv.GetType(); PropertyInfo pi = dgvType.GetProperty(“DoubleBuffered”, BindingFlags.Instance | BindingFlags.NonPublic); pi.SetValue(dgv, setting, null); } It turns double buffering on for DataGridView objects. Just call DoubleBuffered() on your DGV. Hope it … Read more