c# - Enum Properties not updating across CollectionViews -


i have class, "mainviewmodel" includes observable collection of colourmappingviewmodel, , references out 2 other viewmodels, 1 used update colourmappingviewmodels (colourcontrollerviewmodel), , 1 contains collectionview used display particular subset of these colourmappingviewmodels (colourselectionviewmodel). both these classes passed observablecollection bind to.

colourmappingviewmodel has 2 properties: color , , type.

public class colourmappingviewmodel : viewmodel, {     public color textcolour     {                 {             return (color)colorconverter.convertfromstring(_colourmapping.textcolour);         }         set         {             _colourmapping.textcolour = value.tostring().remove(1, 2);             onpropertychanged();         }     }       public colourmappingusagetype type     {                 {             return _colourmapping.usage;         }         set         {                             _colourmapping.usage = value;             onpropertychanged()         }     } 

}

colourcontroller includes datagrid, type column including combobox binds collection of enum types , "type" property so:

  itemssource="{binding types, mode=oneway}"   selectedvalue="{binding type, mode=twoway, updatesourcetrigger=propertychanged}"  

and similarly, combobox containing colourlist, bound so:

itemssource="{binding datacontext.colourslist,              relativesource={relativesource findancestor, ancestortype={x:type view:colourcontroller}}}"              selecteditem="{binding backgroundcolour, mode=twoway, updatesourcetrigger=propertychanged}" 

the collectionview on colourselectionviewmodel filters list based on value of "type", , have combobox on colourselection view bound collectionview.

now. if update "textcolour" of in colourcontroller, reflected in colourselector - can see changes.

if update 'type', though, whole thing falls on stackoverflowexception due "onpropertychanged()" being repeatedly called. question is, why!?

update code to:

public color textcolour {         {         //it faster convert in set, not in         //get called more         return (color)colorconverter.convertfromstring(_colourmapping.textcolour);     }     set     {         var converted = value.tostring().remove(1, 2);         if (_colourmapping.textcolour == converted) return;         _colourmapping.textcolour = converted;         onpropertychanged();     } }   public colourmappingusagetype type {         {         return _colourmapping.usage;     }     set     {                         if (_colourmapping.usage == value) return;         _colourmapping.usage = value;         onpropertychanged()     } } 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -