I've got a basic page in a Windows 10 Universal App that I'm using the new binding pattern with.
I'm loading a ViewModel into a public property on the MainPage.xaml.cs code-behind. This ViewModel contains a bunch of properties that I am binding to properties on my controls and they work just fine.
public sealed partial class MainPage : Page
{
public MainViewModel MainVM { get; set; }
public MainPage()
{
this.MainVM = SimpleIoc.Default.GetInstance<MainViewModel>();
this.InitializeComponent();
}
... more stuff that isn't important ...
}
Now I want to bind to the SelectionChanged event on a ListView. I'm using the following in my ViewModel:
public void AccountsSelectionChanged(object sender, SelectionChangedEventArgs e)
{
.... stuff ....
}
And this is in my 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 the crazy thing... for a while, this has worked! A few hours later, I started getting this error:
Error CS0122 'MainPage.MainPage_obj1_Bindings.MainPage_obj1_BindingsTracking.cache_MainVM' is inaccessible due to its protection level
It's very possible I made a change somewhere that caused this condition, but I have no idea where. If I remove the binding to the SelectionChanged event, then this error goes away. But it was WORKING before! I don't know what else to do. I've tried cleaning the solution and rebuilding without the binding, then putting it back in and it doesn't work.
I've verified that every possible class involved is both public and has a public constructor. Restarting VS2015 RC didn't help and neither did rebooting Windows 10 (build 10074).
EDIT - I have verified that the x:Bind pattern for events does work when I put the handler directly in code-behind on MainPage.xaml.cs with this XAML:
SelectionChanged="{x:Bind AccountsSelectionChanged}"
My viewmodel is public, public, public. I am not sure what I am missing.
Can anyone provide something else to try?