Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
210
Column Visibility fails sometimes when using GroupColumns in XamGrid
posted

When using GroupColumns in XamGrid if the Visbility of Columns within a GroupColumn become Colapsed the GroupColumn will also become colasped.  This is the behaviour expected however once the GroupColumn has become colapsed even when the Columns within that GroupColumn become Visible again the GroupColumn will never become Visible again.

Here is an example:

Xaml:

    <Window.Resources>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
    </Window.Resources>
    <DockPanel>
        <StackPanel DockPanel.Dock="Top">
            <CheckBox Name="A" IsChecked="True">A</CheckBox>
            <CheckBox Name="B" IsChecked="True">B</CheckBox>
        </StackPanel>
        <ig:XamGrid AutoGenerateColumns="False" ItemsSource="{Binding DataSource}">
            <ig:XamGrid.Columns>
                <ig:GroupColumn Key="AB" >
                    <ig:GroupColumn.Columns>
                        <ig:TextColumn Key="A" Visibility="{Binding Source={x:Reference A}, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                        <ig:TextColumn Key="B" Visibility="{Binding Source={x:Reference B}, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                    </ig:GroupColumn.Columns>
                </ig:GroupColumn>
            </ig:XamGrid.Columns>
        </ig:XamGrid>
    </DockPanel>
Code behind:
    public partial class MainWindow
    {
        public IEnumerable<Field> DataSource { get; set; }
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;
            DataSource =
                new[]
                    {
                        new Field {A = 1, B = 2},
                        new Field {A = 2, B = 3},
                        new Field {A = 3, B = 4}
                    };
        }
    }
    public class Field
    {
        public int A { get; set; }
        public int B { get; set; }
    }
In the example above if you uncheck then recheck A leaving B checked the column Visibility changes as expected.  However if you uncheck both A and B then recheck either or both, neither will show again.
I have also tried doing a MultiBinding on the GroupColumn to the Visibility of it's children Columns but that also did not help.  Does anyone know of a solution to this?
Thanks