In memory FlowDocument to XPS with working DataBinding

It costs me some time and nerves to figure this out, but finally ive got this working.


var flowDocument = (FlowDocument)Application.LoadComponent( new Uri( @"MyFlowDocument.xaml", UriKind.Relative ) );

doc.DataContext = this;

var package = Package.Open( new MemoryStream(), FileMode.Create, FileAccess.ReadWrite );
var packUri = new Uri( "pack://temp.xps" );
PackageStore.RemovePackage( packUri );
PackageStore.AddPackage( packUri, package );

var xpsDocument = new XpsDocument( package, CompressionOption.SuperFast, packUri.ToString() );

var paginator = ((IDocumentPaginatorSource)flowDocument).DocumentPaginator;

new XpsSerializationManager( new XpsPackagingPolicy( xpsDocument ), false )
.SaveAsXaml( paginator );

Viewer.Document = xpsDocument.GetFixedDocumentSequence();</code><strong></strong>

The key part here to get the binding to work is this call:


Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.SystemIdle,
new DispatcherOperationCallback(arg => null ), null);

Ive got this tip from the blog of Mark Nijhof. I dont know why this is need, but i assume that it needs one Dispatcher run to expand the DataBinding.

I like jabber

The last time i play a lot with the instant messaging protocol jabber. It is amazing! Here a few benefits of it:

* distributed server model similar to smtp
* supports multi user chat rooms like irc
* transports which creating a server side bridge for a lot of services and other instant messaging services
* the protocol is open

I hope over the time this is good replacement for irc and icq.

Comments are fixed now

Ive noticed that there are propblems with posting comments on my blog. The ReCAPTCHA Plugin had a errer in his configuration, that is know fixed.

For all how dont know what ReCAPTCHA is. Its another tool which can confine the amount of spam ive got from spam bots and at the same time the user helps to digitalize a book.

Subscribing to GoogleGroups with every EMail address

I don’t know if there is an place in GoogleGroups user interface to achieve this, but i did not find it. But you can subscribe with every EMail address to a GoogleGroups when sending a mail to the address of the group and add an “-subscribe” before the @. An Example:

You can subscribe to the group TiddlyWiki@googlegroups.com when you sending a mail to TiddlyWiki-subscribe@googlegroups.com . I ever give this message the subject “subscribe” but i don’t know if important.

Have fun!

I am addicted on ReSharper

The last weeks I’ve play a lot with Visual Studio 2008. It is a fantastic product and the startup time is amazing fast, but without ReSharper ( the 2008 version with C#3.0 support isn’t released yet ) it is so circuitous to write code. So it isnt really funny to write code without ReSharper.

For all who dost know what ReSharper is. It is a Visual Studio Extension with extend C# and VB.Net with various features.

A few examples:

  • From lightning fast property and constructor creation
  • It shows you all your unused code
  • It shows you common coding mistakes
  • Creates delegation proxy’s with a few clicks
  • and a lot more

Change assembly search path within MSBuild

Today I’ve try to create a simple MSBuild task. It should load all NHibernate mappings, use the configuration to build the session factory and write all exceptions as errors to MSBuild build log ( and in Visual Studio output window ). Sounds pretty simple?….it isn’t :-)

First i have to change the assembly search path to allow NHibernate to find the in mapping referenced assembly’s.

To do this, my first idea was to create a new appdomain, it isn’t possible to change the assembly search path of a running appdomain ( this where my msbuild task is running in ).  This works when you only running your MsBuild tasks from command line…but not in Visual Studio. All custom tasks there running in partial trust environment and you can no create appdomain’s within it.

After a long while of testing, i gave it up and move to “ToolTask”. ToolTask allow you to run another process as tool. This process is not running in partial trust, so you can create appdomain’s there.

This works, but you have to do all the interprocess communication stuff. Ive create input and output temp file where i serialize my parameters only as simple framework types ( when you use your custom types, you have to deal with the changed assembly search path ) and pass the filenames as argument to the tool process.

String interpolation feature wish for C# 4.0

Mitch posted about his wish to integrate a shortcut for formatting in c# vnext.

Let’s say that my code is going to throw and exception, I typically need to build the error message to load into the exception message. That could be expressed as:

throw new Exception(string.Format(”{0}{1}{2}”, a, b, c));

But I think we could have a nicer inline string format syntax:

throw new Exception(  @(”{0}{1}{2}”|a|b|c)  );

I think this should be resolved more like it is in other dynamic languages like boo. Lets take a sample:

throw new Exception( $" {a}{b}{c} " );

The $ (or something other) before means, allow in line variable interpolation in this string literals.

My new blog

First let me introduce myself. My name is Steve Wagner. I live close-by Berlin ( Germany ) and working as an  software developer in the heart of Berlin.

I am focused on Microsoft .Net, but not always on Windows :-)

In this Blog i will write mainly about development and other computer stuff.