I cannot access the Page's ViewModel property in order to bind it to IsVisible Property. I can only bind it if I don't set the BindingContext. Is there a way I can access the page's viewmodel/root property while also setting the BindingContext?
Page XAML:
<eventViews:EventInfoWidget BindingContext="{Binding EventViewModel}" IsVisible="{Binding IsEventInfoWidgetEnabled}" />
<eventViews:AvailableShiftInfoWidget BindingContext="{Binding EventViewModel}" IsVisible="{Binding IsAvailableShiftInfoWidgetEnabled}"></eventViews:AvailableShiftInfoWidget>
ViewModel:
public EventViewModel EventViewModel { get; }
public bool IsEventInfoWidgetEnabled => _IsEventInfoWidgetEnabled.Value;
public bool IsAvailableShiftInfoWidgetEnabled => _IsAvailableShiftInfoWidgetEnabled.Value;
The IsVisibile Property can only be bind to the EventViewModel Object Properties, but I would like to bind it to the page's viewmodel
Found the solution, you have to specify the source and then set the path to the property.
First set the name of the page
<pages:AppContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
x:Name="ShiftPage">
After that just bind IsVisible Property to the right source
IsVisible="{Binding Source={x:Reference ShiftPage}, Path=BindingContext.IsEventInfoWidgetEnabled }"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With