如何在添加项目时自动扩展选项卡控件而不创建滚动条?
我正在使用 WPF 用户控件(选项卡控件)在下面的简化代码中动态添加选项卡项:
....
foreach (string id in ids)
{
TabControl.Items.Add(CreateTabItem(id));
}
private TabItem CreateTabItem(string name)
{
StackPanel txtBlock = new TextBlock();
txtblock.Text = name;
txtBlock.HorizontalAlignment = Horizontalalignment.Center;
panel.Children.Add(txtBlock);
TabItem item = new TabItem();
item.Header = panel;
<SomeControl> control = new <SomeControl>();
item.Content = control;
return item;
}
在 xaml 文件中,我指定以下内容将所有选项卡项堆叠到左列:
MinWidth="100" MinHeight="300" TabStripPlacement="Left"
如何使选项卡控件自动扩展(即拉伸)它的高度以显示我添加的所有选项卡项目? 目前,我必须手动扩展显示窗口的高度才能看到所有选项卡项目。 非常感谢您的见解/提示。
PS:如果您知道如何在选项卡项超过窗口高度时立即出现垂直滚动条(无需向我的控件添加滚动条),如果我的初衷没有答案,我可以解决这个问题。
I am using a WPF user control (tab control) to add tab items dynamically in the simplified code below:
....
foreach (string id in ids)
{
TabControl.Items.Add(CreateTabItem(id));
}
private TabItem CreateTabItem(string name)
{
StackPanel txtBlock = new TextBlock();
txtblock.Text = name;
txtBlock.HorizontalAlignment = Horizontalalignment.Center;
panel.Children.Add(txtBlock);
TabItem item = new TabItem();
item.Header = panel;
<SomeControl> control = new <SomeControl>();
item.Content = control;
return item;
}
In the xaml file I specified the following to stack all my tab items to the left column:
MinWidth="100" MinHeight="300" TabStripPlacement="Left"
How do I make my tab control automatically extending (ie. stretching) its height to show all the tab items as I add them in? For now, I have to manually extend the height of the display window to see all the tab items. Your insights/tips are greatly appreciated.
PS: if you know how to make the vertical scroll bar appears (without adding scroll bar to my control) as soon as the tab items exceed the window height, I can settle for that if there are no answers for my original intent.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为您提供滚动条,该滚动条将在需要时启用。
gets you the scrollbar which will be enabled when needed.