I'm trying to implement a toggle button that permits the user to select between linear or logarithmic axis.
For that I have in my View this ToggleButton:
<ToggleButton Width="40" Height="20" Margin="2" Grid.Row="1" Content="LogX" VerticalAlignment="Center" IsChecked="{Binding LogXChecked, Mode=TwoWay}"/>
In my ViewModel:
private bool _isLogXChecked;
public bool IsLogXChecked
{
get
{
return _isLogXChecked;
}
set
{
_isLogXChecked = value;
RaisePropertyChanged("IsLogXChecked");
LogX();
}
}
But with this implementation I can't get it to work, the IsLogXChecked property does not update when the user presses the ToggleButton, and my method LogX() does not fire.
Where might be the problem? Or how should I bind a ToggleButton to a bool? Thank you.
Your XAML binds to LogXChecked
, but your ViewModel defines this as IsLogXChecked
. Right now, the binding is broken because the property name doesn't match the binding specification.
You can fix this on either side - for example, fix this in the Xaml via:
<ToggleButton Width="40" Height="20" Margin="2"
Grid.Row="1" Content="LogX" VerticalAlignment="Center"
IsChecked="{Binding IsLogXChecked, Mode=TwoWay}" />
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