Re: [aus-dotnet] WPF UI Thread


    [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
    • From: Stephen Price
    • Subject: Re: [aus-dotnet] WPF UI Thread
    • Date: Wed, 25 Jul 2007 01:10:05 -0700

    I'm not sure if this is a nasty work around... but it works better than without. (yeah I think it "smells")
     
    I've put Application.DoEvents() into the RenderList and Print functions (rather than totally rewrite the code) and it actually animates my control (with some stopping and starting). The ideal solution would be to run on its own thread, but I got this idea from years ago when I was writing single threaded apps. And given WPF is essentially single threaded... :)
     
    Cheers,
    Stephen
     
    On 7/25/07, Stephen Price <stephen@xxxxxxxxxxxxxxxx> wrote:
    Looks like an XPS document is being created (not sure if it's a custom library or part of framework) and then doc.RenderList is being passed the ListView.
     
    My understanding of the design of this is that the view object is the view (in the sense of View, Presenter, Model) and that it's just printing the ListView. Comes out looking like a screenshot so the idea of creating a bitmap of the listview then print the bitmap might work. Will have a play. Can't spend too much time on it unfortunately...
     
    Thanks,
    Stephen

     
    On 7/25/07, Paul Stovell < Paul.Stovell@xxxxxxxxxxx> wrote:

    How are you printing the ListView? If it's the entire visible control, you could try converting the Visual to an image and printing the image –

     

    http://www.ericsink.com/wpf3d/3_Bitmap.html

     

    RenderTargetBitmap bmp = new RenderTargetBitmap (
    width, height, 96, 96, PixelFormats.Pbgra32);

    bmp.Render(myListView);

    If it's the items from the ListView, perhaps you could extract the objects from the list first before printing them rather than passing the ListView as a reference. WPF UI elements like the ListView are tightly-bound to the dispatcher (thread) they were created on, and most properties/methods you try to call on them will fail if you call them from another thread.

     

    Regards,

    Paul Stovell
    Readify | Senior Developer
    Microsoft MVP: Visual Developer - Client Application Development

    M: +61 420 314 127 | C: paul.stovell@xxxxxxxxxxx | B: www.paulstovell.net

    From: peter@xxxxxxxxxxx [mailto:peter@xxxxxxxxxxx] On Behalf Of Stephen Price
    Sent: Wednesday, 25 July 2007 9:00 AM
    To: dotnet@xxxxxxxxxxx
    Subject: [aus-dotnet] WPF UI Thread

     

    Hi all,

     

    I've got a WPF problem I'm trying to work around.

     

    I want to display a progress indicator, and have a control with a funky little animated thing on it, but the function I want to display the indicator during blocks the UI thread.

    I tried putting an application.doevents() in after my indicator is called and it does show it but it doesnt animate. Dont have the code handy but the psudocode goes like;

     

    displayProgress();

    view.Print();

    clearProgress();

     

    with the result of the progress indicator being shown then cleared immediately so that you dont see it. (remove the clearProgress and it is shown after the print finishes.)

     

    I think it's the way the view.Print is written... I tried it on its own thread but it seems to want objects in the UI (Its printing a listview).

     

    thanks,

    Stephen






    (Click here for more information on the aus-dotnet mailling list)