0

下面的代码运行良好,但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>
4

2 回答 2

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>
于 2013-01-04T16:40:14.773 回答
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>
于 2013-01-04T15:56:38.027 回答