I'm using this Convention in my project without any issues. Here is a walkthrough:
In the AppBootstrapper.cs
you include the Element Convention among other given Conventions
private static void AddCustomConventions()
{
ConventionManager.AddElementConvention<FrameworkElement>(Control.VisibilityProperty, "Visibility", "IsVisible");
var baseBindProperties = ViewModelBinder.BindProperties;
ViewModelBinder.BindProperties = (frameWorkElements, viewModel) =>
{
BindVisiblityProperties(frameWorkElements, viewModel);
return baseBindProperties(frameWorkElements, viewModel);
};
}
and your helper method:
private static void BindVisiblityProperties(IEnumerable<FrameworkElement> items, Type viewModel)
{
foreach (FrameworkElement element in items)
{
string PropertyName = element.Name + "IsVisible";
var property = viewModel.GetPropertyCaseInsensitive(PropertyName);
if (property != null)
{
var convention = ConventionManager.GetElementConvention(typeof(FrameworkElement));
ConventionManager.SetBindingWithoutBindingOverwrite(
viewModel, PropertyName, property, element, convention, convention.GetBindableProperty(element));
}
}
}
In your PageView.xaml
you place your Controls and provide a x:Name
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button x:Name="StartRecord">start</Button>
<Button x:Name="StopRecord">stop</Button>
<Button x:Name="Foo">foo</Button>
<Button x:Name="Bar">bar</Button>
</StackPanel>
within your PageViewModel.cs
you place a public property
of type bool
with the suffix IsVisible
public bool FooIsVisible { get { return true; } }
public bool BarIsVisible { get { return false; } }