I have followed both examples in this question however I am unable to bind a boolean in my view model to a button in my view. I am using a different button that toggles whether or not the other button should be visible or not, can anyone see what is wrong?
Currently I am trying to bind the boolean to the visibility of the button, this is not working even though I have tested that the boolean is toggling between True/False. The other method I used was to use a data trigger to change the visibility. I have commented out this method as it was not working.
View
<Button Canvas.Left="300" Canvas.Top="235" Click="ShowEquipmentItems" Cursor="Hand" Visibility="{Binding ShowButtons, Converter={StaticResource BooleanToVisibilityConverter}}">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Content">
<Setter.Value>
<StackPanel>
<Image Source="../Images/Green spot icon.png" Height="35" Width="35" />
</StackPanel>
</Setter.Value>
</Setter>
<Setter Property="Visibility" Value="Collapsed"/>
<!--<Style.Triggers>
<DataTrigger Binding="{Binding ShowButtons}" Value="True">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>-->
</Style>
</Button.Style>
</Button>
<Button Canvas.Right="10" Canvas.Top="388" Command="{Binding ToggleButtonCommand}" Cursor="Hand" Height="50" Width="50" />
View Model
public class CabinViewViewModel : BindableBase, ICabinViewViewModel
{
public bool ShowButtons { get; set; }
public DelegateCommand ToggleButtonCommand { get; private set; }
public CabinViewViewModel()
{
ToggleButtonCommand = new DelegateCommand(ToggleButtons, CanToggleButtons);
ShowButtons = true;
}
public void ToggleButtons()
{
ShowButtons = !ShowButtons;
System.Console.WriteLine("Toggle Buttons" + ShowButtons.ToString());
}
public bool CanToggleButtons()
{
return true;
}
}