c# - xaml binding not working as expected -


i have created simple credo (create, review, edit, delete, overview) wpf application cars learn c# , have run issue. when either adding or editing item observable collection, want allow user able browse computer picture associated car. had accomplished in code behind following:

namespace carapp { public partial class mainwindow : window {     public mainwindow()     {         initializecomponent();     }      /// <summary>     /// open browser window when user clicks on 'browse' button     /// </summary>     /// <param name="sender"></param>     /// <param name="e"></param>     private void add_browse_button_click(object sender, routedeventargs e)     {         //send path textbox         addpicturepath.text = this.browse();     }      ///// <summary>     ///// open browser window when user clicks on 'browse' button     ///// </summary>     ///// <param name="sender"></param>     ///// <param name="e"></param>     private void edit_browse_button_click(object sender, routedeventargs e)     {         //send path textbox         editpicturepath.text = this.browse();     }      /// <summary>     /// open browser window , return user selection     /// </summary>     /// <returns>filename</returns>     private string browse()     {         //open browser window         microsoft.win32.openfiledialog dlg = new microsoft.win32.openfiledialog();          //search .png files         dlg.defaultext = ".png";          //show browser         dlg.showdialog();          return dlg.filename;     } } } 

this worked requested remove code behind (which seemed fine because purely ui element, tell me if i'm wrong) application. moved code icommand:

namespace carapp.commands { public class browsecommand : icommand {     public bool canexecute(object parameter)     {         return true;     }      public event eventhandler canexecutechanged     {         add { commandmanager.requerysuggested += value; }         remove { commandmanager.requerysuggested -= value; }     }      public void execute(object parameter)     {         car param = parameter car;          try         {             //open browser window             microsoft.win32.openfiledialog dlg = new microsoft.win32.openfiledialog();              //search .png files             dlg.defaultext = ".png";              //show browser             dlg.showdialog();              //send path textbox             param.picturepath = dlg.filename;         }         catch (nullreferenceexception)         {             console.write("param null in browse");          }      } } } 

now when run application, path not show in textbox, when when click "add list" button, item added displaying proper image. seems though textbox not updating, though have inotification implemented. missing obvious? here relevant xaml code:

<button width="75"     height="23"     margin="10,0,0,0"     horizontalalignment="left"     command="{binding browsecommand}"     commandparameter="{binding newcar}"     content="browse" /> 

and

<textbox x:name="addpicturepath"         width="200"         height="23"         margin="10,0,0,0"         horizontalalignment="left"         scrollviewer.verticalscrollbarvisibility="auto"         text="{binding newcar.picturepath,                     updatesourcetrigger=propertychanged}"         textwrapping="wrap" /> 

if understand correctly, binding newcar.picturepath newcar changing. when notify of property changed, guessing notify newcar object changing (not picturepath). try this; within newcar setter, after setting _newcar = value, update _newcar.picturepath , assuming picturepath notifying properly, should update , give insight how binding working... hope helps!


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -