Textblock doesnt get updated when rendered in memory?

Posted by veechi on Stack Overflow See other posts from Stack Overflow or by veechi
Published on 2010-05-29T06:17:43Z Indexed on 2010/05/29 6:22 UTC
Read the original article Hit count: 201

Filed under:
|

I have a text block which as part of a custom control.I added the custom control as a child of grid which in turn is added as child of a Canvas.All of these contorl are instantiated in memory and are not rendered on the UI.When I update the value of the TextBlock and emboss the canvas on an image, the updated value doesnt appear on the embossed image.Here is the code snippet:-

        System.Windows.Controls.Canvas embossCanvas = new System.Windows.Controls.Canvas();
        System.Windows.Controls.Grid grid = new Grid();
        MyControl myctrl= new MyControl();
        int wd = (int)myctrl.ActualWidth;
        int ht = (int)myctrl.ActualHeight;
        embossCanvas.Width = wd;
        embossCanvas.Height = ht;
        grid.Children.Add(myctrl);
        embossCanvas.Children.Add(grid);

        myctrl.txtBlk.UpdateLayout();
        grid.UpdateLayout();
        embossCanvas.Measure(new System.Windows.Size(embossCanvas.Width, embossCanvas.Height));
        embossCanvas.Arrange(new System.Windows.Rect(0, 0, embossCanvas.Width, (int)embossCanvas.Height));
        embossCanvas.UpdateLayout();

        RenderTargetBitmap renderBmp = new RenderTargetBitmap(wd, ht, 96, 96, System.Windows.Media.PixelFormats.Default);
        renderBmp.Render(embossCanvas);

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf