Is there a way to make binding happen in a Silverlight control that is created in code?
I'm wanting to print a UserControl
that binds to a view model. I create the control in code because if I don't it prints off the edge of the page. Apparently, there is no way to control the size or scale of a printed UIElement
without screwing up the element that is on the Silverlight page. So I create the 'UserControl' with the following code in the PrintPage
event of a PrintDocument
:
private void OnPrintPage(object sender, PrintPageEventArgs e)
{
PurchaseReceipt purchaseReceipt = new PurchaseReceipt();
purchaseReceipt.DataContext = _receiptData;
purchaseReceipt.Visibility = System.Windows.Visi开发者_开发百科bility.Visible;
purchaseReceipt.Margin = new Thickness(25.0);
purchaseReceipt.Width = e.PrintableArea.Width - 50.0;
e.PageVisual = purchaseReceipt;
}
The problem is that binding doesn't work, or doesn't work in time. Is there a way to force an element to bind?
精彩评论