I need to create an attached property which communicates with some service inside it's PropertyChanged event handler. E. g.
private static void IsRegisteredPropertyChanged(DependencyObject target,
DependencyPropertyChangedEventArgs e)
{
//how to resolve this without service locator?
IService someService = ServiceLocator.Resolve<IService>();
if ((bool)e.NewValue)
{
someService.Register(target);
}
else
{
someService.Unregister(target);
}
}
As I understand, the event handler will always be static. Is there any way to inject a dependency for this event handler using Unity except with Service Locator pattern? If not then maybe there are any alternatives that let you declaratively register view elements to that service?