以下代码效果不错,但即使ScrollBar
内有大文本,也会禁用垂直TextBlock
。我该如何启用它?
<UserControl.DataContext>
<viewModels:CommentsViewModel/>
</UserControl.DataContext>
<Grid>
<DockPanel >
<TreeView DockPanel.Dock="Top"/>
<Expander Header="Yo" DockPanel.Dock="Bottom" VerticalAlignment="Bottom">
<ScrollViewer HorizontalScrollBarVisibility="Disabled">
<TextBlock TextWrapping="Wrap" MaxHeight="250"
Text="{Binding Article.Article.Content}"/>
</ScrollViewer>
</Expander>
</DockPanel>
</Grid>
答案 0 :(得分:1)
我找到了。
MaxHeight="250"
标记应该不在TextBlock
中,但应该在Grid
中以限制高度。然后它将完美地运作。
<UserControl.DataContext>
<viewModels:CommentsViewModel/>
</UserControl.DataContext>
<Grid>
<DockPanel >
<TreeView DockPanel.Dock="Top"/>
<Expander Header="Yo" DockPanel.Dock="Bottom" VerticalAlignment="Bottom">
<Grid MaxHeight="250">
<ScrollViewer HorizontalScrollBarVisibility="Disabled">
<TextBlock TextWrapping="Wrap"
Text="{Binding Article.Article.Content}"/>
</ScrollViewer>
</Grid>
</Expander>
</DockPanel>
</Grid>
答案 1 :(得分:0)
如果您只是显示文字,请确保它可以使用TextBox
:
<Expander Header="Yo" DockPanel.Dock="Bottom" VerticalAlignment="Bottom">
<Grid IsReadOnly="True">
<TextBox TextWrapping="Wrap" MaxHeight="250"
Text="{Binding Article.Article.Content}"/>
</Grid>
</Expander>