c# - MVVM - Following a tutorial but not working as intended -


regarding : https://www.tutorialspoint.com/mvvm/mvvm_wpf_data_bindings.htm

fairly new mvvm following tutorial learn more it.

however have reached point in tutorial (that link above) not appear working. when update text boxes text block supposed update via databindings

so here code.

model : https://pastebin.com/lu2cw2py

using system.componentmodel;  namespace midb_mvvm.model {     public class inventorymodel     {     }     public class inventoryitems : inotifypropertychanged     {         #region variables          private string _barcode;         private string _category;         private string _location;         private string _status;         private string _sizecase;         private string _name;         private string _manufacturer;         private string _mpn;         private string _supplier;         private string _spn;         private string _value;         private string _tolerance;         private string _voltage;         private string _powerrating;         private string _rohs;         private string _description;          #endregion          public string barcode         {                         {                 return _barcode;              }             set             {                 if (_barcode != value)                 {                     _barcode = value;                     raisepropertychanged("barcode");                 }             }         }         public string category         {                         {                 return _category;              }             set             {                 if (_category != value)                 {                     _category = value;                     raisepropertychanged("category");                 }             }         }         public string location         {                         {                 return _location;              }             set             {                 if (_location != value)                 {                     _location = value;                     raisepropertychanged("location");                 }             }         }         public string status         {                         {                 return _status;                }             set             {                 if (_status != value)                 {                     _status = value;                     raisepropertychanged("status");                 }             }         }         public string sizecase         {                         {                 return _sizecase;             }             set             {                 if (_sizecase != value)                 {                     _sizecase = value;                     raisepropertychanged("sizecase");                 }             }         }         public string name         {                         {                 return _name;             }             set             {                 if (_name != value)                 {                     _name = value;                     raisepropertychanged("name");                 }             }         }         public string manufacturer         {                         {                 return _manufacturer;             }             set             {                 if (_manufacturer != value)                 {                     _manufacturer = value;                     raisepropertychanged("manufacturer");                 }             }         }         public string mpn         {                         {                 return _mpn;             }             set             {                 if (_mpn != value)                 {                     _mpn = value;                     raisepropertychanged("mpn");                 }             }         }         public string supplier         {                         {                 return _supplier;             }             set             {                 if (_supplier != value)                 {                     _supplier = value;                     raisepropertychanged("supplier");                 }             }         }         public string spn         {                         {                 return _spn;             }             set             {                 if (_spn != value)                 {                     _spn = value;                     raisepropertychanged("spn");                 }             }         }         public string value         {                         {                 return _value;             }             set             {                 if (_value != value)                 {                     _value = value;                     raisepropertychanged("value");                 }             }         }         public string tolerance         {                         {                 return _tolerance;             }             set             {                 if (_tolerance != value)                 {                     _tolerance = value;                     raisepropertychanged("tolerance");                 }             }         }         public string voltage         {                         {                 return _voltage;             }             set             {                 if (_voltage != value)                 {                     _voltage = value;                     raisepropertychanged("voltage");                 }             }         }         public string powerrating         {                         {                 return _powerrating;             }             set             {                 if (_powerrating != value)                 {                     _powerrating = value;                     raisepropertychanged("powerrating");                 }             }         }         public string rohs         {                         {                 return _rohs;             }             set             {                 if (_rohs != value)                 {                     _rohs = value;                     raisepropertychanged("rohs");                 }             }         }         public string description         {                         {                 return _description;             }             set             {                 if (_description != value)                 {                     _description = value;                     raisepropertychanged("description");                 }             }         }          public string categorylocation         {             { return _category + " " + _location; }         }          private string constring = properties.settings.default.inventorydbconnstring;          public event propertychangedeventhandler propertychanged;          private void raisepropertychanged(string property)         {             if (propertychanged != null)             {                 propertychanged(this, new propertychangedeventargs(property));             }         }     } } 

viewmodel: https://pastebin.com/fhtfvyx8

using system.collections.objectmodel;  using midb_mvvm.model;  namespace midb_mvvm.viewmodel {     public class inventoryviewmodel     {         public inventoryviewmodel()         {             loadinventory();         }          public observablecollection<inventoryitems> inventories         {             get;             set;         }          public void loadinventory()         {             observablecollection<inventoryitems> inventories = new observablecollection<inventoryitems>();              inventories.add(new inventoryitems             {                 barcode = "mres01",                 category = "resistor",                 description = "mres01",                 location = "resbox",                  manufacturer = "rs",                 mpn = "mres01",                 name = "smdres",                 powerrating = "10",                 rohs = "yes",                 sizecase = "0402",                 value = "10",                 status = "new",                 supplier = "farnell",                 tolerance = "10",                  voltage = "10",                 spn = "01234589"             });             inventories.add(new inventoryitems             {                 barcode = "mres02",                 category = "resistor",                 description = "mres02",                 location = "resbox",                 manufacturer = "rs",                 mpn = "mres01",                 name = "smdres",                 powerrating = "20",                 rohs = "yes",                 sizecase = "0603",                 value = "20",                 status = "new",                 supplier = "farnell",                 tolerance = "20",                 voltage = "20",                 spn = "23456789"             });             inventories.add(new inventoryitems             {                 barcode = "mres03",                 category = "resistor",                 description = "mres03",                 location = "resbox",                 manufacturer = "rs",                 mpn = "mres01",                 name = "smdres",                 powerrating = "30",                 rohs = "yes",                 sizecase = "0805",                 value = "30",                 status = "new",                 supplier = "farnell",                 tolerance = "30",                 voltage = "30",                 spn = "987654321"             });              inventories = inventories;         }      } } 

view/usercontrol xaml: https://pastebin.com/4blftss0

<usercontrol x:class="midb_mvvm.views.inventoryview"            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"               xmlns:d="http://schemas.microsoft.com/expression/blend/2008"               xmlns:local="clr-namespace:midb_mvvm.views"              xmlns:viewmodel = "clr-namespace:midb_mvvm.viewmodel"               xmlns:vml ="clr-namespace:midb_mvvm.vml"              vml:viewmodellocator.autohookedupviewmodel="true"              mc:ignorable="d" d:designheight="300" d:designwidth="300">      <!--<usercontrol.datacontext>        <viewmodel:inventoryviewmodel/>     </usercontrol.datacontext>-->      <grid>         <stackpanel horizontalalignment = "left">             <itemscontrol itemssource = "{binding path = inventories}">                 <itemscontrol.itemtemplate>                     <datatemplate>                          <stackpanel orientation = "horizontal">                             <textbox text = "{binding path = category, mode = twoway}"                                       width = "100" margin = "3 5 3 5"/>                              <textbox text = "{binding path = location, mode = twoway }"                                       width = "100" margin = "0 5 3 5"/>                              <textblock text = "{binding path = categorylocation, mode = oneway}"                                         margin = "0 5 3 5"/>                          </stackpanel>                      </datatemplate>                 </itemscontrol.itemtemplate>             </itemscontrol>         </stackpanel>     </grid> </usercontrol> 

would able tell me doing wrong here? trying figure out why text block not updating when value changed in text boxes?

when set category , location properties should raise propertychanged event twice, 1 property name , other notify categorylocation had changed:

    public string category     {                 {             return _category;          }         set         {             if (_category != value)             {                 _category = value;                 raisepropertychanged("category");                 raisepropertychanged("categorylocation");             }         }     }     public string location     {                 {             return _location;          }         set         {             if (_location != value)             {                 _location = value;                 raisepropertychanged("location");                 raisepropertychanged("categorylocation");             }         }     } 

otherwise view not have way know changing 1 of 2 properties affect third.


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -