Reputation: 1445
Why are all event handlers in WPF declared with private access by default?
private void CommonClickHandler(object sender, RoutedEventArgs e)
Is it a pattern?
Upvotes: 0
Views: 111
Reputation: 2902
Because they are not supposed to be used by other classes, so this is default behaviour.
BTW: Use commands in stead and System.Windows.Interactivity, a framework such as galasoft and follow the MVVM pattern.
<UserControl.....>
<UserControl.DataContext>
<local:YourViewModel/> <!-- Use a viewmodel locator instead -->
</UserControl.DataContext>
<Button Content="Click Me" Command={Binding SomeCommand}/>
</UserControl>
VM:
public class YourViewModel : ViewModelBase
{
public ICommand SomeCommand{get; set;}
public YourViewModel()
{
InitStuff();
}
protected virtual void InitStuff()
{
SomeCommand = new RelayCommand(ButtonClicked);
}
private void ButtonClicked()
{
// DO stuff
}
}
Upvotes: 1