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
250
Ability to Expand All/Collapse All in XamDataGrid with buttons in HeaderPrefixArea
posted

I have hierarchical xamDataGrid (3 layers) in which I place a +/- button in the HeaderPrefixArea which we would like to expand and collapse upon the +/- button click. Looked at the post (http://forums.infragistics.com/forums/p/37606/218282.aspx) and learnt that there is known issue here. Want to know if that is fixed in release 2010.2. If not, is there any work around for that? I tried the workaround solution given in the above posting but it is not working as desired.

Below is the code:

<Style TargetType="{x:Type igDP:HeaderPrefixArea}" >

    <Setter Property="Template">

        <Setter.Value>

            <ControlTemplate TargetType="{x:Type igDP:HeaderPrefixArea}">                          

                <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Stretch">

                    <Button Content="+" HorizontalAlignment="Left"

                            vm:RecordsExpandAllExtension.IsExpandedAll="{Binding RelativeSource={RelativeSource AncestorType={x:Type igDP:XamDataGrid}}, Path=DataContext.IsExpandAllClicked, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"

                            Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type igDP:XamDataGrid}}, Path=DataContext.ExpandAllCommand}"

                            Width="15"/>

                    <Button Content="-" HorizontalAlignment="Left"

                            vm:RecordsExpandAllExtension.IsCollapsedAll="{Binding RelativeSource={RelativeSource AncestorType={x:Type igDP:XamDataGrid}}, Path=DataContext.IsCollapseAllClicked, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"

                            Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type igDP:XamDataGrid}}, Path=DataContext.CollapseAllCommand}"

                            Width="15"/>

                </StackPanel>

                </ControlTemplate>

        </Setter.Value>

    </Setter>

</Style>

 

private bool _isExpandAllClicked = false;

public bool IsExpandAllClicked

{

    get { return _isExpandAllClicked; }

    set

    {

        if (_isExpandAllClicked != value)

        {

            _isExpandAllClicked = value;

            this.RaisePropertyChanged("IsExpandAllClicked");

        }

    }

}

 

private bool _isCollapseAllClicked = false;

public bool IsCollapseAllClicked

{

    get { return _isCollapseAllClicked; }

    set

    {

        if (_isCollapseAllClicked != value)

        {

            _isCollapseAllClicked = value;

            this.RaisePropertyChanged("IsCollapseAllClicked");

        }

    }

}

 

 

protected void XdgOnInitializeRecord(InitializeRecordEventArgs e)

{

    if (IsExpandAllClicked)

        e.Record.IsExpanded = true;

    else

        e.Record.IsExpanded = false;

}

 

 

public class RecordsExpandAllExtension

{

    public static bool GetIsExpandedAll(UIElement obj)

    {

        using (Tracing.Source.FunctionScope())

        {

            return ExceptionHandling.Policy.Process(() =>

            {

                return (bool)obj.GetValue(IsExpandedAllProperty);

            });

        }

    }

 

    public static void SetIsExpandedAll(UIElement obj, bool value)

    {

        using (Tracing.Source.FunctionScope())

        {

            ExceptionHandling.Policy.Process(() =>

            {

                obj.SetValue(IsExpandedAllProperty, value);

            });

        }

               

    }

 

    public static bool GetIsCollapsedAll(UIElement obj)

    {

        using (Tracing.Source.FunctionScope())

        {

            return ExceptionHandling.Policy.Process(() =>

            {

                return (bool)obj.GetValue(IsCollapsedAllProperty);

            });

        }

           

    }

 

    public static void SetIsCollapsedAll(UIElement obj, bool value)

    {

            using (Tracing.Source.FunctionScope())

        {

            ExceptionHandling.Policy.Process(() =>

            {

                obj.SetValue(IsCollapsedAllProperty, value);

            });

        }

    }

 

    public static readonly DependencyProperty IsExpandedAllProperty =

    DependencyProperty.RegisterAttached(

    "IsExpandedAll",

    typeof(bool),

    typeof(RecordsExpandAllExtension),

    new UIPropertyMetadata(false, OnIsExpandedChanged));

 

    public static readonly DependencyProperty IsCollapsedAllProperty =

    DependencyProperty.RegisterAttached(

    "IsCollapsedAll",

    typeof(bool),

    typeof(RecordsExpandAllExtension),

    new UIPropertyMetadata(false, OnIsCollapsedChanged));

 

    public static void OnIsExpandedChanged(DependencyObject depObj, DependencyPropertyChangedEventArgs e)

    {

        using (Tracing.Source.FunctionScope())

        {

            ExceptionHandling.Policy.Process(() =>

            {

                if (e.NewValue is bool)

                {

                    if ((bool)e.NewValue)

                    {

                        XamDataGrid grid = Utilities.GetAncestorFromType(depObj, typeof(XamDataGrid), true) as XamDataGrid;

                        if (grid != null)

                        {

                            foreach (DataRecord dr in grid.Records)

                            {

                                if (dr.IsExpanded == false)

                                    dr.IsExpanded = true;

                            }

                        }

                    }

                }

            });

        }

    }

 

    public static void OnIsCollapsedChanged(DependencyObject depObj, DependencyPropertyChangedEventArgs e)

    {

        using (Tracing.Source.FunctionScope())

        {

            ExceptionHandling.Policy.Process(() =>

            {

                if (e.NewValue is bool)

                {

                    if ((bool)e.NewValue)

                    {

                        XamDataGrid grid = Utilities.GetAncestorFromType(depObj, typeof(XamDataGrid), true) as XamDataGrid;

                        if (grid != null)

                        {

                            foreach (DataRecord dr in grid.Records)

                            {

                                if (dr.IsExpanded == true)

                                    dr.IsExpanded = false;

                            }

                        }

                    }

                }

            });

        }

    }

}