积极答复者
ScrollViewer 滚动条

问题
-
我在ScrollViewer里写了一个textblock, 编译后滚动条出现在webview上,textblock不能滚动,如何让滚动条滚动的时候textblock和webview同时滚动?
<ScrollViewer
HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollMode="Disabled" ScrollViewer.VerticalScrollMode="Enabled"
ScrollViewer.ZoomMode="Disabled">
<Grid><RowDefinition Height="Auto"/>
<RowDefinition Height="*"/><Textblock Text="{binding Title}" />
<Webview x:Name="detailview" Grid.Row="1" /></Grid>
</ScrollViewer>
- 已编辑 gray_cat, -3.1.0 2014年6月18日 7:46
答案
-
你好,我看过你的代码,大概清楚你的问题在哪了。
1,首先你给两行定义的高度为auto和*,同时也没有给TextBlock或者WebView设定高度,这样ScrollViewer会自动调整高度。
所以你需要给两个东西设定高度,这样才能让ScrollBar显示,我这里设定的是ScrollViewer高度为600,而Gird的高度加起来为800,那么ScollBar必然出现:
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollMode="Disabled" ScrollViewer.VerticalScrollMode="Enabled" ScrollViewer.ZoomMode="Disabled" Height="600"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <TextBlock Height="400" Text="asdsadasdasdas" /> <WebView Height="400" x:Name="detailview" Grid.Row="1" Source="http://www.microsoft.com" /> </Grid> </ScrollViewer>
2,我估计你说的问题是发生在鼠标处于WebView范围内,这个时候鼠标的事件都会被WebView所捕捉,并且被WebView处理掉,也就出现了你所说的滑动的时候TextBlock不动的情况。
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- 已标记为答案 Jamles HezModerator 2014年6月27日 3:18
-
这个略微有点难度,不过还是可以通过JavaScript注入的方式来获取。
使用下面语句来获取:
string[] arguments = { "document.documentElement.clientWidth.toString()" }; var height = await webview.InvokeScriptAsync("eval", arguments);
-James<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- 已标记为答案 gray_cat, -3.1.0 2014年6月26日 6:48
全部回复
-
你好,
你可能需要重新排版,让滚动条与WebView控件不重叠。
另外,我不是很明白你说让滚动条滚动的时候TextBlock和WebView同时滚动的意思?如果需要的话,可以把ScrollViewer的HorizontalOffset绑定给TextBlock或者WebView就行啦。不过可能还需要一个Convertor类来帮忙。
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- 已编辑 Jamles HezModerator 2014年6月17日 8:13
-
那也很简单,吧TextBlock和WebView放在一个Grid或者StackPanel下,然后把这个容器放在ScrollView里面,就可以一起向上滚动啦。
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later. -
你好,我看过你的代码,大概清楚你的问题在哪了。
1,首先你给两行定义的高度为auto和*,同时也没有给TextBlock或者WebView设定高度,这样ScrollViewer会自动调整高度。
所以你需要给两个东西设定高度,这样才能让ScrollBar显示,我这里设定的是ScrollViewer高度为600,而Gird的高度加起来为800,那么ScollBar必然出现:
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollMode="Disabled" ScrollViewer.VerticalScrollMode="Enabled" ScrollViewer.ZoomMode="Disabled" Height="600"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <TextBlock Height="400" Text="asdsadasdasdas" /> <WebView Height="400" x:Name="detailview" Grid.Row="1" Source="http://www.microsoft.com" /> </Grid> </ScrollViewer>
2,我估计你说的问题是发生在鼠标处于WebView范围内,这个时候鼠标的事件都会被WebView所捕捉,并且被WebView处理掉,也就出现了你所说的滑动的时候TextBlock不动的情况。
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- 已标记为答案 Jamles HezModerator 2014年6月27日 3:18
-
这个略微有点难度,不过还是可以通过JavaScript注入的方式来获取。
使用下面语句来获取:
string[] arguments = { "document.documentElement.clientWidth.toString()" }; var height = await webview.InvokeScriptAsync("eval", arguments);
-James<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- 已标记为答案 gray_cat, -3.1.0 2014年6月26日 6:48
-
小很多?是固定的值还是几十或者几百px?
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later. -
你好,
我这里给你的代码有两个问题
1,我们目的是为了获取高度,但是可能是我手误,写成了clientWidth,不知道你改了没有
2,我昨天也看了一下这个问题,找到一个blog,感觉挺有用的: http://www.cnblogs.com/ConjurerYang/archive/2009/08/12/1544251.html, 你可以去看一下document.body.clientHeight 和 document.documentElement.clientHeight 的区别
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- 已建议为答案 Jamles HezModerator 2014年6月27日 3:18