I am trying to setup and binding with a ToggleButton
to change the visibility of columns in a DataGrid
. I am following this post The issue being is that converter never fires and I don't know why.
My code is as follows:
<DataGridTemplateColumn Header="My Header"
Visibility="{Binding IsChecked,
ElementName=AdvancedToggleButton,
Converter={StaticResource booleanToVisaulConverter}}" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<!-- Elements removed for brevity-->
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
The Converter is this
<Page.Resources>
<local:BooleanToVisaulConverter x:Key="booleanToVisaulConverter" />
</Page.Resources>
With the code behind;
public class BooleanToVisaulConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool visibility = (bool)value;
return visibility ? Visibility.Visible : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
Visibility visibility = (Visibility)value;
return (visibility == Visibility.Visible);
}
}
edit: @Breeze found a mistake that booleanToVisaulConverter
was not actually pointing to BooleanToVisaulConverter
. This has been fixed but still not firing. Asked for the ToggleButton code;
<ToggleButton Name="AdvancedToggleButton" Content="Advanced" />