gpt4 book ai didi

c# - 如何实现具有最低高度要求的 Telerik RadPageView?

转载 作者:太空宇宙 更新时间:2023-11-03 11:29:56 27 4
gpt4 key购买 nike

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

我已经尝试在每个 RadPageViewPage 上设置 MinimumSize 属性。但是,当我这样做时,页面 View 页面“溢出”到页面选择器的顶部。我原以为 handle (控件的可拖动部分)会自动调整大小以满足最低高度要求。

请查看下面我的示例应用程序的屏幕截图:

问题:

enter image description here

期望:

enter image description here

更新:

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

无论如何,这是片段:

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

仍然很好奇我是否需要这段代码。控件已经可以做到这一点了吗?

最佳答案

我发布了同样的 question在 Telerik 论坛上,发现该控件实际上不支持我上面提出的问题。

最后,我调整了函数来计算所需的高度,而不是对它们进行硬编码。一旦计算出高度,该函数就会显示或隐藏所需的正确页数。该函数现在由扩展类中的 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);
}
}

关于c# - 如何实现具有最低高度要求的 Telerik RadPageView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8139619/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com