Если вы хотите общее решение, вот что я закончил на основе: Добавление соглашения для IsEnabled в Caliburn.Micro
Обратите внимание на переопределение BindActions и BindProperties, чтобы вы могли проверять видимость для объектов, с которыми связаны действия.
protected override void Configure()
{
base.Configure();
ConventionManager.AddElementConvention<UIElement>(UIElement.VisibilityProperty, "Visibility", "VisibilityChanged");
var baseBindProperties = ViewModelBinder.BindProperties;
ViewModelBinder.BindProperties =
(frameWorkElements, viewModel) =>
{
BindVisiblityProperties(frameWorkElements, viewModel);
return baseBindProperties(frameWorkElements, viewModel);
};
// Need to override BindActions as well, as it's called first and filters out anything it binds to before
// BindProperties is called.
var baseBindActions = ViewModelBinder.BindActions;
ViewModelBinder.BindActions =
(frameWorkElements, viewModel) =>
{
BindVisiblityProperties(frameWorkElements, viewModel);
return baseBindActions(frameWorkElements, viewModel);
};
}
void BindVisiblityProperties(IEnumerable<FrameworkElement> frameWorkElements, Type viewModel)
{
foreach (var frameworkElement in frameWorkElements)
{
var propertyName = frameworkElement.Name + "IsVisible";
var property = viewModel.GetPropertyCaseInsensitive(propertyName);
if (property != null)
{
var convention = ConventionManager
.GetElementConvention(typeof(FrameworkElement));
ConventionManager.SetBindingWithoutBindingOverwrite(
viewModel,
propertyName,
property,
frameworkElement,
convention,
convention.GetBindableProperty(frameworkElement));
}
}
}