c# - WPF Combobox and selectedvalue not updating as expected -


i've had history of difficulty combobox , other item controls not being responsive way i'd expect.

now have combobox bound list, , when user selects item, perform function, want return list item 0.

everytime reset selectedvalue element 0, ignored. understanding how these bindings work appreciated.

my xaml:

<combobox itemssource="{binding path=documentsavailable, updatesourcetrigger=propertychanged}" displaymemberpath="name" selectedvaluepath="name" selectedvalue="{binding path=selecteddocument, mode=twoway, updatesourcetrigger=propertychanged}" issynchronizedwithcurrentitem="true" /> 

my document class:

    public class document     {         public document(string name, bool enable)         {             this.name = name;             this.enabled = enable;         }         public document(fileinfo file, bool enable)         {             this.name = file.name;             this.file = file;             var uri = new system.uri(file.fullname);             this.url = uri.absoluteuri;             this.enabled = enable;         }         public string name { get; set; }         public fileinfo file { get; set; }         public string url { get; set; }         public bool enabled { get; set; }     } 

my getters , setters:

    private observablecollection<document> _documentsavailable = null;     public observablecollection<document> documentsavailable     {                  {             if (_documentsavailable == null)             {                 fileinfo[] files = applicationcontext.current.package.getdocumentsfiles();                 _documentsavailable = new observablecollection<document>();                 _documentsavailable.add(new document("select document", false));                 foreach (fileinfo fi in files)                 {                     _documentsavailable.add(new document(fi, true));                 }             }             return _documentsavailable;          }     }      private string _selecteddocument = "select document";     public string selecteddocument     {         { return _selecteddocument; }         set         {             if (value != _selecteddocument)             {                 _selecteddocument = value;                 raisepropertychanged("selecteddocument");                 document document = _documentsavailable.where(x => x.name.equals(_selecteddocument)).firstordefault();                 if (document != null && document.enabled) showdocument(document);             }         }     } 

and code run after selection:

    public void showdocument(document document)     {         dialogs.documentviewmodel viewmodel = applicationcontext.current.navigation.getviewmodel(typeof(dialogs.documentviewmodel)) dialogs.documentviewmodel;         viewmodel.showdialog(document);         selecteddocument = _documentsavailable[0].name;     } 

the problem i'm having after showing document, want return "select document", stays on previous selection. (the last line of code in showdocument method.

any advice appreciated.

surely need this

public void showdocument(document document) {     dialogs.documentviewmodel viewmodel = applicationcontext.current.navigation.getviewmodel(typeof(dialogs.documentviewmodel)) dialogs.documentviewmodel;     viewmodel.showdialog(document);            selecteddocument = "select document"; } 

Comments