开发者

Display properties in Header and bind to nested collection with David Poll's CollectionPrinter

开发者 https://www.devze.com 2023-02-17 23:58 出处:网络
I need to print an object in Silverlight 4.A (much simplified) version of the class is this: public class Order

I need to print an object in Silverlight 4. A (much simplified) version of the class is this:

public class Order
{
    public string CompanyName {get;set;}
    public string OrderReference {get;set;}
    public List<string> Items {get;set;}

}

I'm trying to use David Poll's CollectionPrinter to achieve this, as it handles so many of the crazy idiosyncrasies surrounding Silverlight printing that it seems like a sensible route.

However, being a CollectionPrinter the ItemsSource needs to be a collection, so I can only get as far as printing the Items from the class in the body, not the CompanyName or the OrderReference in the header.

The layout I'm after is:

Page 1

Header, containing CompanyName and OrderReference

Start of Items list

Page 2 (and subsequent pages...)

Rest of Items list

I thought I might be able to get a开发者_Go百科way with binding the CollectionPrinter's ItemsSource to a List<Order> containing my one order, and then implement a ListBox bound to Items in the BodyTemplate, but this fails to paginate (presumably because it requires multiple items in order to calculate pagination).

Does anyone have any suggestions as to how to handle this scenario, either with the CollectionPrinter or without?


I ended up completely changing the way this worked and implementing an HTML/JavaScript solution, passing the objects as JSON and writing a custom JSON parser to populate an HTML template, in a similar style to any of the other templating solutions available.

Aside from being simpler to implement than Silverlight printing, it also performed much faster as the printed files were a few kilobytes rather than several megabytes.

Roll on Silverlight 5 and its Postscript Vector Printing API...

0

精彩评论

暂无评论...
验证码 换一张
取 消