This is a migrated thread and some comments may be shown as answers.

RadPageView Minimum Height Question

3 Answers 182 Views
PageView
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 15 Nov 2011, 04:38 PM
I have my RadPageView control setup as ViewMode "Outlook" in my winforms C# application. In my requirement, I have a limited space to display the control (about 600px of height). When the control has more than 5 pages added, the view panel (the open area above the page selectors) is made smaller and cuts off the content. I would like to know if there is a way to enforce a minimum height on this area so that the control will automatically collapse page selectors it cannot fit in this confined space. I need about 300px of height for each page.

I have already tried setting the MinimumSize property on each RadPageViewPage. However, when I do this, the page view page "bleeds" over the top of the page selectors. I was expecting the grip to automatically resize to allow for this minimum height requirement.

Please see the screen shots from my sample application attached.

Edit:
I am using the RadPageView control from Q2 2011 SP1

Update:
I was able to achieve what I was looking for using the following code snippet and calling it from the "Initialized" and "Resized" events. I would still like to know if the control already supports this without having to write this snippet.

private void adjustPageViewGrip()
{
    RadPageViewOutlookElement viewElement = (RadPageViewOutlookElement)radPageView.ViewElement;
    int minHeight = 310;
    int itemHeight = radPageView.SelectedPage.Item.Size.Height;
    int selectedPageHeight = radPageView.SelectedPage.Height;
 
    if (selectedPageHeight < minHeight)
    {
        int hide = (int)Math.Ceiling((double)(minHeight - selectedPageHeight) / (double)itemHeight);
        if (hide > 0)
        {
            viewElement.HideItems(hide);
        }
    }
    else if ((selectedPageHeight + itemHeight) >= minHeight)
    {
        int show = (int)Math.Floor((double)(selectedPageHeight - minHeight) / (double)itemHeight);
        if (show > 0)
        {
            viewElement.ShowItems(show);
        }
    }
}


3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 18 Nov 2011, 10:43 AM
Hello Mark,

Thank you for writing.

Here is my suggestion for your scenario. Since you are mentioning that after adding five pages the content is getting cut off, you can check if five pages are added, and if so, simply collapse the newly added pages, by using the HideItems method of RadPageVIewOutlookElement. Here is an example of my suggestion:
private void radButton1_Click(object sender, EventArgs e)
{
    RadPageViewPage page = new RadPageViewPage();
    page.Text = "Page Text";
    radPageView1.Pages.Add(page);
 
    if (radPageView1.Pages.Count > 5)
    {
        RadPageViewOutlookElement element = radPageView1.ViewElement as RadPageViewOutlookElement;
        element.HideItems(1);
    }
}

I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.

All the best,
Stefan
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

0
Mark
Top achievements
Rank 1
answered on 18 Nov 2011, 03:17 PM
Hello Stefan,

Thank you for your reply. Unfortunately that code snippet won't help me. I should have mentioned that the control needs to be anchored so that it'll grow/shrink as the form is resized. I ended up using the code snippet I posted in my question to do this for me. I was just curious if maybe I overlooked something that the RadPageView control was capable of. Sounds like I still need my code snippet.

Here's my updated function. I'm calling this function in the OnLoad, Initialized, Resized, and SelectedPageChanged events in an extended class.

/// <summary>
/// Adjusts the position of the Outlook overflow grip.
/// </summary>
public void AdjustOutlookViewOverflowGrip()
{
    if (ViewMode == PageViewMode.Outlook && SelectedPage != null)
    {
        // Fix rendering bug by hiding RadPageViewPage's that are not currently selected
        foreach (RadPageViewPage page in Pages)
        {
            if (page == SelectedPage)
            {
                page.Show();
            }
            else
            {
                page.Hide();
            }
        }
     
        // Elements from control
        RadPageViewOutlookElement outlookElement = (RadPageViewOutlookElement)ViewElement;
        OverflowItemsContainer overflowItemsContainer = (OverflowItemsContainer)GetChildAt(0).GetChildAt(4);
 
        // Selected page and item heights
        int selectedPageMinHeight = (SelectedPage.MinimumSize.Height > ContentMinimumHeight ? SelectedPage.MinimumSize.Height : contentMinimumHeight);
        int pageSelectorHeight = SelectedPage.Item.Size.Height;
 
        // Show or hide items
        if (pageSelectorHeight > 0 && selectedPageMinHeight > 0)
        {
            // Calculate content area height
            int contentAreaHeight =                
                (
                    Size.Height -
                    (
                        from element in ((RadPageViewOutlookElement)ViewElement).Children
                        where
                        (
                            element.Visibility != ElementVisibility.Collapsed
                            &&
                            (
                                element is RadPageViewLabelElement
                                || element is OutlookViewOverflowGrip
                                || element is RadPageViewOutlookItem
                                || element is OverflowItemsContainer
                            )
                        )
                        select element.Size.Height + element.Margin.Vertical
                    )
                    .Sum()
                );
 
            if (contentAreaHeight < selectedPageMinHeight)
            {
                // Factor in OverflowItemsContainer height if it's currently collapsed
                int overflowItemsHeight = (overflowItemsContainer.Visibility == ElementVisibility.Collapsed ? overflowItemsContainer.Size.Height : 0);
 
                // Not enough space available... hide items
                int hide = (int)Math.Ceiling((double)(selectedPageMinHeight - contentAreaHeight + overflowItemsHeight) / (double)pageSelectorHeight);
                if (hide > 0)
                {
                    outlookElement.HideItems(hide);
                }
            }
            else if (contentAreaHeight >= (selectedPageMinHeight + pageSelectorHeight))
            {
                // More space available... show items
                int show = (int)Math.Floor((double)(contentAreaHeight - selectedPageMinHeight) / (double)pageSelectorHeight);
                if (show > 0)
                {
                    outlookElement.ShowItems(show);
                }
            }
        }
 
        // Set overflow container visiblity
        overflowItemsContainer.Visibility = (outlookElement.GetHiddenItems().Length > 0 ? ElementVisibility.Visible : ElementVisibility.Collapsed);
    }
}

Thanks,
Mark
0
Stefan
Telerik team
answered on 21 Nov 2011, 05:15 PM
Hello Mark,

In this case, your approach is the correct one to use.

Greetings,
Stefan
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

Tags
PageView
Asked by
Mark
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Mark
Top achievements
Rank 1
Share this question
or