I am puzzled by a (I thought) simple thing to implement; make a UI element visible depending on a binding to a view model. I use the mvvmlight framework. When the binding (boolean) is set to true
the visibility binding does not react to the change.
XAML:
<Button
Command="{Binding NavigationCommand}" CommandParameter="{StaticResource Back}"
Visibility="{x:Bind (Visibility) ViewModel.ShowNavigationButtons}">
<Image Source="../../../Resources/NavigateBack.PNG"/>
</Button>
Code behind:
public sealed partial class MainPage
{
public MainPage()
{
InitializeComponent();
DataContext = new MainViewModel();
}
public MainViewModel ViewModel => DataContext as MainViewModel;
}
ViewModel:
public class MainViewModel : ViewModelBase
{
private bool _showNavigationButtons;
public RelayCommand BrakingCommand { get; }
public bool ShowNavigationButtons
{
get => _showNavigationButtons;
set { Set(() => ShowNavigationButtons, ref _showNavigationButtons, value); }
}
public MainViewModel()
{
BrakingCommand = new RelayCommand(() =>
{
ShowNavigationButtons = true;
NavigationCommand.RaiseCanExecuteChanged();
});
}
}
I also tried to bind "the WPF way" :
Visibility="{Binding ShowNavigationButtons, Converter{StaticResource BoolToVisibilityConverter}">
But that results in the exact same problem; the view doesn't react on the changed property.
Help is much appreciated,
BoolToVisibilityConverter
declared? – Dit