8
I've came across an interesting issue for which I've found no explanation yet...
Given the very simple MVVM WPF application below, why is the list bound to the combo box only if its visibility in the ViewModel is set to public ?
Changing the TestList visibility to internal raises no error or warning at compile time but leaves the combo box empty at run time.
Quoting the official documentation: internal types or members are accessible only within files in the same assembly.
And this issue is happening despite the fact that the View and the ViewModel are defined in the same assembly.
Here is how the code looks like:
Model:
class TestModel
{
internal List<string> Musketeers { get; private set; }
public TestModel()
{
Musketeers = new List<string> { "Athos", "Porthos", "Aramis" };
}
}
View:
<Window x:Class="TestWpfApplication.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<ComboBox Width="250" Height="25" ItemsSource="{Binding TestList}" />
</Grid>
</Window>
ViewModel:
class TestViewModel : INotifyPropertyChanged
{
TestModel myModel = new TestModel();
public List<string> TestList
{
get
{
return myModel.Musketeers;
}
}
// INotifyPropertyChanged members are below ...
}