Welcome to the Xceed Community | Help
Community Search  
More Search Options

GroupByControl show/hide

Sort Posts: Previous Next
  •  06-25-2009, 6:58 AM Post no. 22005

    GroupByControl show/hide

    Hi,

    im searching a way howto programaticaly show and hide GroupByControl in my wpf grid. I've master/detail setup, so i need this also for all of my details.

    i know that using following xaml code i will have GroupByControl visible

                        <xcdg:TableView UseDefaultHeadersFooters="False">
                            <xcdg:TableView.FixedHeaders>
                                <!-- we will have show grouping control -->
                                <DataTemplate>
                                    <xcdg:GroupByControl xcdg:TableView.CanScrollHorizontally="False"/>
                                </DataTemplate>
     

    so i think that, that in case of "show" i'd need to add  such DataTemplate into FixedHeaders and Headers of all Details

    and in case of "hide" i'd need remove this DataTemplate from headers...

     

    is my idea good or wrong?  any1 able to provide me some example code howto do it?

     

     (c# pls)

    Filed under:
  •  06-25-2009, 9:47 AM Post no. 22010 in reply to 22005

    Re: GroupByControl show/hide

    What you can do is create an implict style that targets GroupByControl and that has a setter for its Visibility property that is bound to a dependency property that is defined, for example, on the MainWindow. This property should be of type Visibility and when you change its value programmatically, the GroupByControl's Visibility property should be updated automatically, resulting in it being shown or hiddem.


    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  06-25-2009, 10:30 AM Post no. 22019 in reply to 22010

    Re: GroupByControl show/hide

    Hi jenny,

    pls remember i have master/detail setup...

    if i understand right, with this style and property bound to it, it should change visibility of all GroupByControl headers, so in master and all it's details at once...this would be great, but it has one problem. GroupByControl headers would have been already defined in xaml.

    but my goal is a bit different:

    i want use toggleButton, that should show/create (even if does not exits initialy) or hide/remove GroupByCountrol headers in master and all it's details.

    so if i follow your point with style, how can i create GroupByControl headers for master and all it's details in case they have not been defined in xaml?

     

    other option:

    i've seen appoach that is used in TableView demo to manage fixed headers, they are simply recreated each time, maybe i should folow it?

    so i know that i can Add and Remove from FixedHeaders, but how can i achive it also for details?

     


  •  06-25-2009, 1:28 PM Post no. 22041 in reply to 22019

    Re: GroupByControl show/hide

    With an implicit style, you would not have a problem since it will be applied to all GroupByControls regardless of their location and regardless of if they are defined in XAML beforehand.. For example:

    <Style TargetType="{x:Type xcdg:HierarchicalGroupByControl}">

        <Setter Property="Visibility"

                Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:Window1}}, Path=GroupByControlVisibility}" />

    </Style>


    <Style TargetType="{x:Type xcdg:GroupByControl}">                   

        <Setter Property="Visibility"

                Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:Window1}}, Path=GroupByControlVisibility}" />

    </Style> 

     

    Where GroupByControlVisibility is a dependency property located on Window1 that is changed when a button is clicked to collapse or make visible the GroupByControls.

    This is the option that I would use rather than removing and readding DataTemplates to the collections. 


    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  06-26-2009, 3:27 AM Post no. 22068 in reply to 22041

    Re: GroupByControl show/hide

    Jenny:

    With an implicit style, you would not have a problem since it will be applied to all GroupByControls regardless of their location and regardless of if they are defined in XAML beforehand..

    ok, i understand your point of view, but my problem still remains. i mean how can i create programaticaly  GroupByControls in case they have not been defined in xaml?

     so:

    1.howto find out that GroupHeaderControls are defined or not (all of them, in master and all details) ?

    2.howto define/create them if, in case they have not been defined (all of them, in master and all details) ?

     

    also i've noticed someth strange, when i try

    <DataTemplate><xcdg:GroupByControl xcdg:TableView.CanScrollHorizontally="False" Visibility="Visible"/></DataTemplate>

    GroupHeaderControl  is  normaly visible but when i try

    <DataTemplate><xcdg:GroupByControl xcdg:TableView.CanScrollHorizontally="False" Visibility="Hidden"/></DataTemplate>

    GroupHeaderControl  is not visible, but it's area is still used with white rectangle, so effective area of grid is still consumed


    is it intended behaviour or bug? i tho it would work like in TableView demo

     

    note, that im using Office2007BlueTheme.

     

     

  •  06-26-2009, 9:30 AM Post no. 22075 in reply to 22068

    Re: GroupByControl show/hide

    Using Hidden simply hides the element but its "rectangle" will remain. Using Collapsed will both hide the element and its rectangle.

    1- By default, the grid will contain a HierarchicalGroupByControl if master/detail is enabled or a GroupByControl if master/detail is not enabled. No other sections of the grid have a GroupByControl by default. 

    2- You can define a GroupByControl for all detail levels by adding a DataTemplate that defines a GroupByControl to the Headers section of the DefaultDetailConfiguration, which is defined on the grid. 


    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  06-26-2009, 9:45 AM Post no. 22076 in reply to 22075

    Re: GroupByControl show/hide

    thanx for answers, for now i've decided to use groupByControl only for master table, and i know it's possible (u can see in code below) to do it also for details, but it's kinda masochism Smile

    here's what i did

     xaml:

            <!-- we will have grouping control, if desired -->
            <DataTemplate x:Key="groupByControlTemplate">
                <xcdg:GroupByControl xcdg:TableView.CanScrollHorizontally="False" />
            </DataTemplate>


    code behind:

            /// <param name="sender">should be toggle button, that has been clicked</param>
            /// <param name="e"></param>
            public void HandleXceedGridToggleGroup(object sender, RoutedEventArgs e)
            {
                if (sender != null && sender is ToggleButton)
                {
                    bool isChecked = ((ToggleButton)sender).IsChecked.Value == true ? true : false;
                    DataTemplate templateGroupByControl = this.FindResource("groupByControlTemplate") as DataTemplate;
                    if (templateGroupByControl != null)
                    {
                        if (isChecked && !this.View.FixedHeaders.Contains(templateGroupByControl))
                            this.View.FixedHeaders.Insert(0, templateGroupByControl);
                        if (!isChecked && this.View.FixedHeaders.Contains(templateGroupByControl))
                            this.View.FixedHeaders.Remove(templateGroupByControl);

                        // it could work also for deailts, but some more problems would have to be solved (headers are not added when details are not expanded)
                        //foreach (DetailConfiguration conf in GetDetailConfigurations(this.DetailConfigurations))
                        //{
                        //    if (isChecked && !conf.Headers.Contains(templateGroupByControl))
                        //        conf.Headers.Insert(0, templateGroupByControl);
                        //    if (!isChecked && conf.Headers.Contains(templateGroupByControl))
                        //        conf.Headers.Remove(templateGroupByControl);
                        //}
                    }
                }
            }
     

  •  07-16-2009, 5:07 AM Post no. 22652 in reply to 22076

    Re: GroupByControl show/hide

    ok jenny was absolutely right, my above solution works, but it happens that some rows seem to dissapear ocasionaly,i think it's due loose of viewport or someth...anyway here's working example similar to what jenny was telling to do...it is done with filterRow, but the same way would work with groupByControl:

    1.u need something where u will dynamicaly change filterrow visibility, it can be some property, or as i used property in a singleton class:

        public class ConfigurationData : INotifyPropertyChanged
        {
            public static readonly ConfigurationData Singleton = new ConfigurationData();
           
            private Visibility _filterRowVisibility = Visibility.Collapsed;
            public Visibility FilterRowVisibility
            {
                get { return _filterRowVisibility; }
                set
                {
                    _filterRowVisibility = value;
                    this.RaisePropertyChanged("FilterRowVisibility");
                }
            }

            #region INotifyPropertyChanged Members

            public event PropertyChangedEventHandler PropertyChanged;

            protected void RaisePropertyChanged(string name)
            {
                if (this.PropertyChanged != null)
                {
                    this.PropertyChanged(this, new PropertyChangedEventArgs(name));
                }
            }

            #endregion
        }

    2. u have to configure filterRow to be by default visible for master table and all it's childs like this:

                <xcdg:DataGridControl>

                    <!-- we will have Default headers and footer for all child, and also we will see by default FilterRow for all childs -->
                    <xcdg:DataGridControl.DefaultDetailConfiguration>
                        <xcdg:DefaultDetailConfiguration UseDefaultHeadersFooters="True">
                            <xcdg:DefaultDetailConfiguration.Headers>
                                <!-- we will have also filter row by default -->
                                <DataTemplate>
                                    <xcdg:FilterRow />
                                </DataTemplate>
                            </xcdg:DefaultDetailConfiguration.Headers>
                        </xcdg:DefaultDetailConfiguration>
                    </xcdg:DataGridControl.DefaultDetailConfiguration>
                       
                    <xcdg:DataGridControl.View>
                        <xcdg:TableView UseDefaultHeadersFooters="False" ColumnStretchMode="Last">
                            <xcdg:TableView.FixedHeaders>

                                <!-- we will have column headers by default -->
                                <DataTemplate>
                                    <xcdg:ColumnManagerRow />
                                </DataTemplate>
                           
                                <!-- we will have filter row by default -->
                                <DataTemplate>
                                    <xcdg:FilterRow />
                                </DataTemplate>

                            </xcdg:TableView.FixedHeaders>
                        </xcdg:TableView>
                    </xcdg:DataGridControl.View>
                </xcdg:DataGridControl>
     

    3. define a style that would target filterrow and set it's visibility according to your property (in singleton in our case)

    and in addition we have datatrigger that would hide filterrow always, in case there are no rows to filter

     

            <!-- we have configered to have FilterRow for master table and also every child (with DataGridControl.DefaultDetailConfiguration)
                now with this style we let FilterRow to be visible only when want to (FilterRowVisibility) and also there must be some data rows to filter -->
            <Style TargetType="{x:Type xcdg:FilterRow}">
                <Setter Property="MinHeight" Value="20"></Setter>
                <!-- show FilterRow only when we want to -->
                <Setter Property="Visibility" Value="{Binding Source={x:Static local:ConfigurationData.Singleton}, Path=FilterRowVisibility}"></Setter>
                <!-- always hide FilterRow when there are no items -->
                <Style.Triggers>
                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(xcdg:DataGridControl.DataGridContext).Items.Count}"
                            Value="0">
                        <Setter
                          Property="Visibility"
                          Value="Collapsed" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
     

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.