I am trying some different things using MVVM. In our ViewModel properties which are bind to View are public. I am taking example of a button binding. Here is a simple sample.
View.xaml:
<Button Content="Test Button" Command="{Binding TestButtonCommand}" />
ViewModel.cs
private ICommand _testButtonCommand;
public ICommand TestButtonCommand
{
get { return _testButtonCommand?? (_testButtonCommand= new RelayCommand(SomeMethod)); }
}
Here my question is that can we make TestButtonCommand
internal instead of public? Internal means it is accessible to current project so their should not be any problem doing that? But when I tried to do that it didn't worked. Adding a breakpoint in getter was not hit. So why we cannot make it internal?
Here is the link from msdn.
http://msdn.microsoft.com/en-us/library/ms743643.aspx
The properties you use as binding source properties for a binding must be public properties of your class. Explicitly defined interface properties cannot be accessed for binding purposes, nor can protected, private, internal, or virtual properties that have no base implementation.
Why we cannot do this?
In case of access internal is same as public if working in the same project. Then why we cannot use internal here? There must be a reason that these should be public, and I am looking for that reason.
internal ICommand TestButtonCommand { ...... }