WPF:是否可以使路径大小适应布局大小,但仍然拉伸它?
我正在尝试设置 TabItem 标题的样式,使用路径来定义标题的形状。
我陷入了一个似乎无法解决的问题:
如果我将路径 Stretch 属性设置为“无”,那么如果 TabItem 标头中的文本很长,它就不会缩放。
如果我将路径拉伸属性设置为“填充”,它将拉伸得如此之大,以至于每个 TabItem 标头将与 TabControl 具有相同的宽度 - 这意味着每行只有一个非常宽的 TabItem 标头...
您知道一种拉伸方法吗布局的路径(取决于 TabItemHeader 内容),但不是更多?
如果有人能在这方面帮助我,我会非常高兴...当我寻找解决方案时,这很烦人。
谢谢 :-)
I'm trying to style a TabItem Header, using a path to define the shape of the header.
I'm stuck in a problem that I can't seem to resolve :
If I set the path Stretch property to "None", it won't scale if the text in my TabItem Header is long.
If I set the path Stretch property to "Fill", it will stretch so much that each TabItem Header will be the same width as the TabControl - which mean only one very wide TabItem Header per line...
Do you know a way to stretch the path to the layout (depending on the TabItemHeader Content), but not more?
I would be very pleased if somebody can help me on this... it's been an annoying while I'm looking for a solution.
Thank you :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您不添加任何示例代码但说您的 HeaderTemplate 如下所示时,您可以将路径的宽度绑定到 TextBlock 的 ActualWidth ,这很困难。
It's hard when you don't add any sample code but say that your HeaderTemplate looks like below then you can bind the Width of the Path to the ActualWidth of the TextBlock.
但要注意渲染性能!只要 UI 尚未正确渲染,绑定到 ActualWidth 和 ActualHeight 就会导致绑定错误。绑定错误的代价是昂贵的...避免这种情况的最佳方法是在调用 SizeChanged 时在代码中设置绑定。这是测量和尺寸确定完成后的第一刻。
But be aware of rendering performance! Binding to ActualWidth and ActualHeight will result in binding errors as long as the UI hasn't been rendered enterly. And binding errors are expensive...The best way to avoid this, is to set up the binding in code when SizeChanged is called. That's the first moment after measuring and sizing has been finished.