none
Render FrameworkElement without outside WPF application RRS feed

  • Question

  • We have a Class, written in F# which is basically a FrameworkElement. Internal there is a VisualCollection which holds the rendered parts - for compositioning i guess. 

    The class itself represent a Graphic-To-Be-Rendered, which in this special case, has to be done without a UI thread and outside of a WPF application. 

    What we do is the following:

    1. Spawn an STA Thread
    2. - Instantiate the Graphics
    3. - Populate with Data
    4. - Render to Bitmap
    5. - Return Synchronized stream
    6. Outside the STA Thread
    7. - Write stream to File

    The file is empty but has the correct width & length. 

    I believe that it is not possible to do this without an App() or a WPF Context of some kind. We're kind of at a loss here. 

    Any Suggestions are welcome, since i've got nothing a the moment. The goal is basically to render something WPF into a FileStream from withing a thread inside a console application. 

    Tuesday, July 9, 2019 8:53 AM

All replies


  • Hi   Friend,

    >>We have a Class, written in F# which is basically a FrameworkElement. Internal there is a VisualCollection which holds the rendered parts - for compositioning i guess. 
      
    I'm not familiar with F#, you may can go to the F# forum for getting suitable.

    >>Any Suggestions are welcome, since i've got nothing a the moment. The goal is basically to render something WPF into a FileStream from withing a thread inside a console application. 

    The following links described how to render a WPF UserControl to a bitmap(C#). It may can give you some help.

    How to render a WPF UserControl to a bitmap without creating a window

    Server-side rendering of WPF UserControl


    Best regards

    Yong Lu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, July 10, 2019 6:48 AM
  • Hi and Thanks for your reply. 

    With combinding some of the solutions i got it working - but with a hack i cannot use in production. But at least now we know a little bit more about the Problem. 

    In F#, whenever we calculate stuff, we run 

    do! Async.SwitchToThreadPool()

    When we are ready for actually drawing stuff, we run

    do! Async.SwitchToContext guiSynchronizationContext

    When debugging, i can get as far as to switching back to the UI Context, but there the execution stops - or the Debugger cannot hit any further breakpoint. 

    No Exception, no Debug output - nothing to work with. The rendered output is empty. 

    Now if we replace all the SwitchToThreadPool commands with SwitchToUIContext ones, the rendering suddenly starts working. Meaning that there is some kind of configuration issue that prevents us from reliably switching between the STA thread and the thread pool. 


    Thursday, July 11, 2019 12:36 PM
  • Hi and Thanks for your reply. 

    With combinding some of the solutions i got it working - but with a hack i cannot use in production. But at least now we know a little bit more about the Problem. 

    In F#, whenever we calculate stuff, we run 

    do! Async.SwitchToThreadPool()

    When we are ready for actually drawing stuff, we run

    do! Async.SwitchToContext guiSynchronizationContext

    When debugging, i can get as far as to switching back to the UI Context, but there the execution stops - or the Debugger cannot hit any further breakpoint. 

    No Exception, no Debug output - nothing to work with. The rendered output is empty. 

    Now if we replace all the SwitchToThreadPool commands with SwitchToUIContext ones, the rendering suddenly starts working. Meaning that there is some kind of configuration issue that prevents us from reliably switching between the STA thread and the thread pool. 



    Hi   Friend,

    I suggest you can go to the F# forum for getting suitable help.

     
    Thank you for your understanding.

    Best regards

    Yong Lu





    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, July 12, 2019 3:06 AM