假设我有以下XAML。
如何实现最外层的Button
具有这样的高度,以便来自TextBlock
的文字完全可见?
<StackPanel>
<Button HorizontalContentAlignment="Stretch" Width="100" >
<DockPanel >
<CheckBox DockPanel.Dock="Left"/>
<Button DockPanel.Dock="Right" Content="X" />
<TextBlock >
some very long text some very long textsome very long textsome very long textsome very long text
</TextBlock>
</DockPanel>
</Button>
</StackPanel>
答案 0 :(得分:3)
将TextBlock.TextWrapping
设置为Wrap
,以便在文本到达允许空格的边缘时将文本换行到新行
<TextBlock TextWrapping="Wrap"
Text="some very long text some very long textsome very long textsome very long textsome very long text" />
答案 1 :(得分:0)
添加另一个堆栈面板
<StackPanel>
<Button HorizontalContentAlignment="Stretch" Width="auto" >
<DockPanel>
<CheckBox DockPanel.Dock="Left"/>
<StackPanel>
<Button DockPanel.Dock="Right" Content="x" HorizontalAlignment="Right" />
<TextBlock Text="some very long text some very long textsome very long textsome very long textsome very long text" />
</StackPanel>
</DockPanel>
</Button>
</StackPanel>