如何以最小高度要求实现Telerik RadPageView?

时间:2011-11-15 16:25:11

标签: c# winforms telerik

我的winforms RadPageView控件(Q2 2011 SP1)在我的winforms C#应用程序中设置为ViewMode“Outlook”。根据我的要求,我有一个有限的空间来显示控件(大约600px的高度)。当控件添加的页数超过5页时,视图面板(页面选择器上方的开放区域)会变小并切断内容(下面屏幕截图中的黄色区域)。我想知道是否有办法在这个区域强制执行最小高度,以便控件自动折叠页面选择器,它不能适应这个有限的空间。每页我需要大约300px的高度。

我已经尝试在每个RadPageViewPage上设置MinimumSize属性。但是,当我这样做时,页面查看页面“渗出”在页面选择器的顶部。我期待把手(控制器的可拖动部分)自动调整大小以满足这个最小高度要求。

请参阅我的示例应用程序中的屏幕截图:

问题:

enter image description here

所需

enter image description here

更新

当能够触发“初始化”或“调整大小”事件时,我能够创建一个以编程方式调整手柄位置的功能。我意识到当所选页面也发生变化时,我很可能需要调用此函数。

无论如何,这是片段:

private void adjustPageViewGrip()
{
    RadPageViewOutlookElement viewElement = (RadPageViewOutlookElement)radPageView.ViewElement;
    int minHeight = 300;
    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);
        }
    }
}

仍然 好奇我是否需要此代码。控件是否已经这样做了?

1 个答案:

答案 0 :(得分:2)

我在Telerik论坛上发布了同样的question,发现控件实际上并不支持我上面提到的内容。

最后,我调整了函数来计算所需的高度而不是硬编码。计算出高度后,该功能会显示或隐藏所需的正确页数。该功能现在由扩展类中的OnLoadInitializedResizedSelectedPageChanged事件调用。我也通过折叠它使OutlookViewOverflowGrip不可见,我依靠新代码来调整它的位置。

以下是最终结果的代码:

/// <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);
    }
}