[英]Viewbox containing a TextBlock seems to have minimum height
我正在尝试在 WPF 中构建一个 UI 布局,该布局可以随 window 的大小进行缩放。 这个想法是在左边有一些控件,在右边有一些控件,在中间有一行文本。 如果右边的文本行被裁剪就可以了。 最主要的是所有控件的纵横比都保持不变。
那部分工作正常。 问题是文本的中心线似乎有一个最小高度; 低于这个高度,它将开始垂直剪裁。 如果我将 window 做得很薄,我希望文本继续缩小。 即使在TextBlock
上手动设置FontSize
也不起作用。
请注意,左侧和右侧的控件没有最小宽度; 它们可以无限缩小。
我的 XAML 在这里。 我正在使用 .NET 4.0。
<Window x:Class="TestWpfApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="75" Width="525">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Viewbox Grid.Column="0" Stretch="UniformToFill" Margin="2">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center">A</Button>
<Button Grid.Column="1" Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center">B</Button>
<Button Grid.Column="2" Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center">C</Button>
<Button Grid.Column="3" Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center">D</Button>
</Grid>
</Viewbox>
<Viewbox VerticalAlignment="Top" HorizontalAlignment="Left" Grid.Column="1" Stretch="UniformToFill" Margin="2">
<TextBlock>Here is a bunch of text that may prove to be interesting.</TextBlock>
</Viewbox>
<Viewbox Grid.Column="2" Stretch="UniformToFill" Margin="2">
<Button HorizontalAlignment="Center">X</Button>
</Viewbox>
</Grid>
</Window>
问题是您喜欢水平发生的Viewbox
剪辑,但不希望垂直剪辑。 换句话说,您需要UniformToFill
直到水平剪裁停止,然后您想切换到Uniform
。
要获得这两种行为,您需要Viewbox
的替代方法。 不久前,我在 Stack Overflow 的这个名为ViewboxPanel
的答案中写了一个这样的布局元素的原型:
我刚刚对其进行了测试,至少对于您的示例 XAML,我认为它可以满足您的需求:
<local:ViewboxPanel VerticalAlignment="Top" HorizontalAlignment="Left" Grid.Column="1" Margin="2">
<TextBlock>Here is a bunch of text that may prove to be interesting.</TextBlock>
</local:ViewboxPanel>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.