c# - image control don't change the source when binding changed -


i use event in code notify if image scanned

in viewmodel :

public bitmapimage imageselected {    get{return _imageselected;}    set    {         if (_imageselected == value)         {             return;         }         _imageselected = value;         raisepropertychanged(() => imageselected);    } }  public icommand cmdscan {       {        return new delegatecommand(scan);    } } wpftwain twaininterface = null; private bitmapimage _imageselected = null;  private void scan() {      twaininterface = new wpftwain();     twaininterface.twaintransfer += new twaintransferreadyhandler(twainwin_twaintransfer);     twaininterface.acquire(true); }   private void twainwin_twaintransfer(bitmapimage imagesources) {     imageselected = imagesources; } 

in xaml

<image margin="151,12,356,12" stretch="fill" source="{binding imageselected}" /> 

when scanning multiple images image in windows don't change until scan complete, make break point in twainwin_twaintransfer , been called in evry image scanned , raisepropertychanged also, , when scan completed show last image

any suggestions welcome, i'm new in mvvm

update

the code scan in class twainlib (called twaininterface.acquire(true); )

do {    pxfr.count = 0;    hbitmap = intptr.zero;     twimageinfo  iinf = new twimageinfo();    rc = dsiinf( appid, srcds, twdg.image, twdat.imageinfo, twmsg.get, iinf );    if( rc != twrc.success )    {       closesrc();       return pics;    }     rc = dsixfer( appid, srcds, twdg.image, twdat.imagenativexfer, twmsg.get, ref hbitmap );    if( rc != twrc.xferdone )    {       closesrc();       return pics;    }     rc = dspxfer( appid, srcds, twdg.control, twdat.pendingxfers, twmsg.endxfer, pxfr );    if( rc != twrc.success )    {       closesrc();       return pics;    }    pics.add(hbitmap);    bitmapimage bitmapimage = /*converting hbitmap bitmapimage  */    twaintransferready(bitmapimage);  } while( pxfr.count != 0 ); 

and try twaininterface.acquire(true); in task same result,

i replaced

private void twainwin_twaintransfer(bitmapimage imagesources) { imageselected = imagesources; } 

with

app.current.mainwindow.dispatcher.invoke(dispatcherpriority.input, new threadstart(() => imageselected = imagesources)); 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -