我有一个堆栈面板,如下所示。
<Stackpanel>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
< TextBlock Text="SomeText" Grid.Row="0"/>
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Disabled" >
<TextBlock Text="Some Other Text"/>
</ScrollViewer>
</Grid>
</StackPanel>
我希望第二个文本块有一个垂直滚动条。但它没有显示垂直滚动条。有谁知道这是什么问题?
答案 0 :(得分:2)
这个工作试试这个.cs页面添加这一行txt1.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
<Grid x:Name="LayoutRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<ScrollViewer>
<StackPanel x:Name="RightPanel"
Margin="5,0"
ScrollViewer.HorizontalScrollBarVisibility="Visible"
ScrollViewer.VerticalScrollBarVisibility="Visible">
<TextBox TextWrapping="Wrap" Height="50" x:Name="txt1" Text="Some Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other Text"/>
</StackPanel>
</ScrollViewer>
</Grid>
答案 1 :(得分:0)
尝试这样的事情(在TextBox中设置ScrollViewer Width and Height和TextWrapping):
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Visible"
HorizontalScrollBarVisibility="Disabled"
Width="70" Height="50">
<TextBlock Text="Some Other Text tststssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss"
TextWrapping="Wrap"/>
</ScrollViewer>
答案 2 :(得分:0)
stackpanel
Height
添加到RowDefinition
s TextWrapping
TextBlock
醇>
所以你的代码应该是这样的:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="SomeText" Grid.Row="0"/>
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Disabled" >
<TextBlock TextWrapping="Wrap" Text="Some Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other Text"/>
</ScrollViewer>
</Grid>