c# - x:Bind syntax for event binding giving error CS0122: inaccessible due to protection level -


i've got basic page in windows 10 universal app i'm using new binding pattern with.

i'm loading viewmodel public property on mainpage.xaml.cs code-behind. viewmodel contains bunch of properties binding properties on controls , work fine.

public sealed partial class mainpage : page {     public mainviewmodel mainvm { get; set; }      public mainpage()     {         this.mainvm = simpleioc.default.getinstance<mainviewmodel>();         this.initializecomponent();     } ... more stuff isn't important ... } 

now want bind selectionchanged event on listview. i'm using following in viewmodel:

public void accountsselectionchanged(object sender, selectionchangedeventargs e) {     .... stuff .... } 

and in xaml:

<listview verticalalignment="bottom"           itemssource="{x:bind mainvm.accounts}"           itemtemplate="{staticresource accountitemtemplate}"           selectionmode="single"           selectionchanged="{x:bind mainvm.accountsselectionchanged}"           grid.row="1">     <listview.header>         <textblock>accounts</textblock>     </listview.header> </listview> 

here's crazy thing... while, has worked! few hours later, started getting error:

error cs0122 'mainpage.mainpage_obj1_bindings.mainpage_obj1_bindingstracking.cache_mainvm' inaccessible due protection level

it's possible made change somewhere caused condition, have no idea where. if remove binding selectionchanged event, error goes away. working before! don't know else do. i've tried cleaning solution , rebuilding without binding, putting in , doesn't work.

i've verified every possible class involved both public , has public constructor. restarting vs2015 rc didn't , neither did rebooting windows 10 (build 10074).

edit - have verified x:bind pattern events work when put handler directly in code-behind on mainpage.xaml.cs xaml:

selectionchanged="{x:bind accountsselectionchanged}" 

my viewmodel public, public, public. not sure missing.

can provide else try?

it rather strange. i've got 2 listviews on mainpage. on first, have observablecollection of account classes bound itemssource. have selectionchanged event bound handler on same viewmodel. event giving me problems.

on other listview, want display observablecollection of folder classes, property of selected account.

<listview verticalalignment="top"     margin="0,48,0,0"     itemssource="{x:bind mainvm.selectedaccount.folders, mode=oneway}"     itemtemplate="{staticresource folderitemtemplate}"     grid.row="0">     <listview.header>          <textblock>folders</textblock>     </listview.header>  </listview> 

the selectedaccount set in event handler first listview. had read on blog x:bind command seemed default onetime binding rather oneway, set mode oneway on itemssource. binding going change, assumed appropriate setting.

however, causing problems! removed mode=oneway setting , project compiled fine. strangely, can leave in mode=oneway setting , remove event binding in other listview , compile. can't have both.

i don't know if going affect plans listview @ least can compile now.

edit - half answer... can't binding these constraints. need figure out why happening.

edit 2 workaround stop using event , instead bind selecteditem property on listview. selectionmode needs set single work correctly. also, selecteditem outputs object type, needed setup getter/setter converts object original account class when passing private variable. can set listview property mode=twoway without issues when remove binding event.

edit 3 there 2 workarounds. in general, 1 works always. handle event in codebehind. since viewmodel public property on codebehind, can call public method on viewmodel event handler , put in same parameters (or none).

//codebehind //headersvm viewmodel    private void listview_selectionchanged(object sender, selectionchangedeventargs e)     {         foreach (var item in e.addeditems)             headersvm.selectedheaders.add((models.mailheader)item);         foreach (var item in e.removeditems)             headersvm.selectedheaders.remove((models.mailheader)item);     }  private void backbutton_click(object sender, routedeventargs e)     {         this.headersvm.goback();     } 

otherwise, workaround specific listview's selecteditem can twoway bind selecteditem property. then, create converter convertback method turns object model.

public class objecttoaccountconverter : ivalueconverter {     public object convert(object value, type targettype, object parameter, string language)     {         return value;     }      public object convertback(object value, type targettype, object parameter, string language)     {         if (value != null)             return (models.account)value;         return value;     } }  //in app.xaml resources <converters:objecttoaccountconverter x:key="objecttoaccountconverter "/>  //in page.xaml <listview verticalalignment="top"     margin="0,48,0,0"     itemssource="{x:bind mainvm.accounts}"     itemtemplate="{staticresource accounttemplate}"     selecteditem="{x:bind mainvm.selectedaccount, mode=twoway, converter={staticresouce objecttoaccountconverter }}"     grid.row="0">     <listview.header>          <textblock>folders</textblock>     </listview.header>  </listview> 

or instead of creating converter convert object model, can make property in viewmodel generic object instead of actual class:

 private models.account _selectedaccount = null;   public object selectedaccount  {     { return _selectedaccount; }     set     {         if (_selectedaccount != value)         {            _selectedaccount = (models.account)value;            raisepropertychanged();            raisepropertychanged("folders");         }      }   } 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -