How use a DocumentPaginator asynchronously via GetPageAsync with XpsDocumentWriter? - wpf

The idea here is that I have a DocumentPaginator that I want to use with an XpsDocumentWriter or PrintDialog as both have the option of printing given a paginator. When I use either, i.e. XpsDocumentWriter.Write[Async] or PrintDialog.PrintDocument, the paginator is accesed via GetPage vs. GetPageAsync which I've overridden in derived DocumentPaginator class.
Outside of manually consuming the paginator and feeding Visuals to the document writer, is there a way to trigger the use of the Asyc functions of a DocumentPaginator?

Related

From GDI to WPF: rendering

In GDI you just use System.Drawing.Graphics to manually handle the rendering.
In WPF is DrawingContext the way to go?
https://msdn.microsoft.com/en-us/library/system.windows.media.drawingcontext(v=vs.110).aspx
You could indeed override the OnRender method of a UIElement to define your own rendering instructions but note that this is not an immediate mode rendering API like Windows Forms's OnPaint. In fact there is no such API available in WPF.
The drawing operations of the DrawingContext are not used directly when the OnRender method is invoked. They are instead processed by the rendering thread at a later stage.
So depending on what you are trying to do, overriding the OnRender method may not be your best choice after all. You may want to stick to the "WPF way" of creating composite UI elements.

Calling C# Class method from AngularJs bound object

sorta new with Angular, odds are I can't do it... However,
What I'm trying to do is take a button and use the click event to call the bound objects codebehind method (without use of javascript functions):
i.e.: ng-click="MyClassObject.Method(param)"
Is this possible? and if so, what am I missing? :/
Note the object is bound, and data members are being used elsewhere in the view..

Appropriate layer for a DocumentPaginator

I created a generic Paginator that leverages some Attributes to paginate an IEnumerable of any given type.
At first I placed it in my services project, but now I'm not sure anymore, since afaik every service has to expose an interface, and in this case the DocumentPaginator doesn't. Also, the paginator exposes a GetPage method that returns a DocumentPage, that is actually a View object. Am I wrong? If not, then it must be placed in the Views project.
So I thought an idea may be to create a UserControl (View) or a CustomControl, something like the PrintDialog, that contains all the "preview and print" logic.
What do you think?
Thank you guys!

partial method OnCreated not called when expected

I've extended my domain class on the silverlight client side in a partial class. Specifically, I've added a RelayCommand property that I will be binding a button to. The RelayCommand property needs to be initialized, and so it would seem that the best place to do that would be in the OnCreated partial method.
However I gather that when the object from the server is materialized on the client side its constructor is not called (which seems totally wrong headed to me!) Since it's constructor is not called, it's not calling the OnCreated Method.
Is there a config or a convention for getting this OnCreated partial method to be called as the objects are materialized?
DataContractSerialization does not call the constructor of the objects that it deserializes. This decision was made because with the previous serialization methods in .NET having to always have a default constructor on any object that was going to be serialized was a problem. This is not specific to RIA Services, it was a design decision made when WCF itself was created and there is no configuration to change it.
You can find more information at http://blogs.msdn.com/b/carlosfigueira/archive/2011/09/06/wcf-extensibility-serialization-callbacks.aspx as well as examples of how you can use [OnDeserialized] to replicate the effect of the constructor being called.
However, there is a second issue that may cause you problems. Entities get constructed all the time. For example, any time you call TEntity.GetOriginal a new detached entity is being created and returned from the method. That makes trying to do anything like configuring a RelayCommand a potential performance and stability problem. You are probably better off configuring RelayCommands at the DataService or ViewModel level instead of inside the entity itself.
The partial method OnCreated() is only called when you instantiate an Entity using its default constructor.
If you want to initialize your loaded entities you have to override the OnLoaded method. A boolean is passed to it that specifies if the entity was loaded first time or not.

Triggering a command in the view model based on an action in the view

I am working with the Infragistics XamDatagrid. When an event takes place in the view (new record updated), I would like to call a method in the view model. I can't just listen to the CollectionChanged event of the source in the VM because that event gets triggered once the user begins editing the new row in the grid. The RecordUpdating event gets called when the user finished the edits.
What I am doing now is accessing the DataContext directly and calling the method. The problem is that there is nowhere I can find to attach a Command to the gird that would tigger on the event I am interested, nothing like the Command of a Button.
Generally, what is the best way to call into a VM from a view when there is no Command parameter I can set in the view?
Code-behind glue is fine in most cases, but if you find yourself gluing the same type of thing repeatedly, you can look into Attached Behaviors. Here's one old-school approach the introduces the concepts, but doesn't use the new Behavior class: http://www.codeproject.com/KB/WPF/AttachedBehaviors.aspx
Here is an example using the new Behavior class, including a demonstration of how it integrates with Blend: http://geekswithblogs.net/lbugnion/archive/2009/04/05/using-a-behavior-to-magnify-your-wpf-applications.aspx

Resources