WPF TabItem 内容对齐始终居中
我试图将一些内容放入 TabItem 中,但无法添加填充 TabItem 空间的容器。 我添加的任何内容都会居中显示。
我正在使用 WPF 工具包 (WhistlerBlue.xaml) 中的主题,因此我认为这可能是导致我出现此问题的原因。
我无法删除主题,因为我需要它。 我最多可以更改其中的某些内容,但我是 WPF 的新手,并且不知道应该更改什么。
我的 TabControl 看起来像这样:
<TabControl Margin="0,71.25,0,206.25" Name="tabControl1" TabStripPlacement="Left">
<TabItem Name="tabItem1" FlowDirection="LeftToRight" FontSize="22" Height="200" Width="60" >
<TabItem.Header>
<StackPanel Orientation="Horizontal" >
<Image Height="40" Width="40" Margin="20,0,0,0" VerticalAlignment="Center"></Image>
<TextBlock Margin="15,0,25,0" VerticalAlignment="Center" FontWeight="Bold">
Header
</TextBlock>
</StackPanel>
</TabItem.Header>
<TabItem.Content>
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,0,0,0" >
<TextBlock>Test</TextBlock>
</StackPanel>
</TabItem.Content>
</TabItem>
</TabControl>
有类似的问题,但没有答案: 在 WPF 中,如何获取 tabItem 的内容来填充可用空间?
有人可以帮助我吗? 谢谢。
I'm trying to put some content inside my TabItem, but I can't add a container that fills the space of the TabItem. Anything that I add shows up centered.
I'm using a Theme from WPF Toolkit (WhistlerBlue.xaml), so I think that maybe it's that what is causing me this issue.
I cannot remove the Theme, because I need it. At most I could change something in it, but I'm new to WPF, and don't know what should I be changing.
My TabControl looks like this:
<TabControl Margin="0,71.25,0,206.25" Name="tabControl1" TabStripPlacement="Left">
<TabItem Name="tabItem1" FlowDirection="LeftToRight" FontSize="22" Height="200" Width="60" >
<TabItem.Header>
<StackPanel Orientation="Horizontal" >
<Image Height="40" Width="40" Margin="20,0,0,0" VerticalAlignment="Center"></Image>
<TextBlock Margin="15,0,25,0" VerticalAlignment="Center" FontWeight="Bold">
Header
</TextBlock>
</StackPanel>
</TabItem.Header>
<TabItem.Content>
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,0,0,0" >
<TextBlock>Test</TextBlock>
</StackPanel>
</TabItem.Content>
</TabItem>
</TabControl>
There is similar question, but it don't has the answer: In WPF, how do I get the content of a tabItem to fill available space?
Can someone help me?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,我找到了答案。
主题的 .xaml 从 TabItem 的这些设置开始:
我已将 Center 更改为 Stretch,问题就解决了。
我真的需要从书本上学习 WPF,而不是仅仅尝试。
Ok, I found the answer.
The .xaml of the theme started with these settings for TabItem:
I've changed Center to Stretch, and the problem was solved.
I really need to learn WPF from a book, instead of just trying things out.
使用
Use
<controls1:TabItem HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" >