我有一些內容需要閱讀,加載到瀏覽器控件中。即時閱讀時,我想看看進展情況。以某種方式在Web瀏覽器控件中顯示垂直滾動條?試過ScrollViewer.VerticalScrollVisibility
並把整個網頁瀏覽器放入ScrollViewer,沒有任何工作!在windows phone顯示滾動條瀏覽器控件
0
A
回答
0
..Nobody接聽..
但香港專業教育學院已經找到了解決辦法。不太理想,有點骯髒,但它有效,我現在可以顯示閱讀進度。 http://www.pitorque.de/MisterGoodcat/post/Somethings-Missing-from-the-WebBrowser-Control.aspx的主要思想是在頁面中注入一些javascript並通知瀏覽器關於滾動事件;之後,改變自定義滾動條控件放置在瀏覽器附近的位置。
+0
請問您可以打電話給我,因爲您提供的鏈接目前沒有打開。 – 2013-09-21 09:59:16
1
查看我的解決方案,基於MisterGoodcat的想法。我已經創建了一個自定義的Web瀏覽器控件,它在頁面加載後注入JavaScript。
XAML:
<UserControl x:Class="Wallet.Views.Controls.WebBrowserWithScrollbar"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Platform"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignHeight="480" d:DesignWidth="480">
<Grid>
<phone:WebBrowser
Name="WebBrowserControl"
IsScriptEnabled="True"
Margin="0 0 5 0"
ScriptNotify="WebBrowser_OnScriptNotify">
</phone:WebBrowser>
<ScrollBar x:Name="DisplayScrollBar"
Orientation="Vertical"
HorizontalAlignment="Right"
VerticalAlignment="Stretch"
Minimum="0"
Maximum="100"
Value="0"
Visibility="Collapsed"/>
</Grid>
後面的代碼:
/// <summary>
/// Adds a vertical scrollbar to the normal WebBrowser control
/// </summary>
public partial class WebBrowserWithScrollbar : UserControl
{
#region Dependency Properties
public static readonly DependencyProperty SourceProperty = DependencyProperty.Register(
"Source", typeof(string), typeof(WebBrowserWithScrollbar), new PropertyMetadata(string.Empty, OnSourcePropertyChanged));
#endregion
#region Fields
private int _visibleHeight;
private int _scrollHeight;
#endregion
#region Constructors
public WebBrowserWithScrollbar()
{
InitializeComponent();
this.LoadCompleted += this.WebBrowserControlLoadCompleted;
}
#endregion
#region Event Handlers
public event LoadCompletedEventHandler LoadCompleted
{
add
{
WebBrowserControl.LoadCompleted += value;
}
remove
{
WebBrowserControl.LoadCompleted -= value;
}
}
public event EventHandler<NotifyEventArgs> ScriptNotify
{
add
{
WebBrowserControl.ScriptNotify += value;
}
remove
{
WebBrowserControl.ScriptNotify -= value;
}
}
public event EventHandler<NavigationEventArgs> Navigated
{
add
{
WebBrowserControl.Navigated += value;
}
remove
{
WebBrowserControl.Navigated -= value;
}
}
public event EventHandler<NavigatingEventArgs> Navigating
{
add
{
WebBrowserControl.Navigating += value;
}
remove
{
WebBrowserControl.Navigating -= value;
}
}
public event NavigationFailedEventHandler NavigationFailed
{
add
{
WebBrowserControl.NavigationFailed += value;
}
remove
{
WebBrowserControl.NavigationFailed -= value;
}
}
#endregion
#region Properties
public string Source
{
get
{
return (string)this.GetValue(SourceProperty);
}
set
{
this.SetValue(SourceProperty, value);
}
}
#endregion
#region Static Methods
private static void OnSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var controlWrapper = d as WebBrowserWithScrollbar;
if (controlWrapper != null)
{
var webBrowser = controlWrapper.WebBrowserControl;
var newSource = e.NewValue as string;
Uri uri;
if (webBrowser != null &&
newSource != null &&
e.NewValue != e.OldValue &&
!string.IsNullOrEmpty(newSource) &&
Uri.TryCreate(newSource, UriKind.Absolute, out uri))
{
webBrowser.Source = uri;
}
}
}
#endregion
#region Methods
private void WebBrowserControlLoadCompleted(object sender, NavigationEventArgs e)
{
this.InitializeScrollBarScript();
}
private void WebBrowser_OnScriptNotify(object sender, NotifyEventArgs e)
{
var parts = e.Value.Split('=');
if (parts.Length != 2)
{
return;
}
int number;
if (!int.TryParse(parts[1], out number))
{
return;
}
if (parts[0] == "scrollHeight")
{
_scrollHeight = number;
if (_visibleHeight > 0)
{
DisplayScrollBar.Maximum = _scrollHeight - _visibleHeight;
}
}
else if (parts[0] == "clientHeight")
{
_visibleHeight = number;
if (_scrollHeight > 0)
{
DisplayScrollBar.Maximum = _scrollHeight - _visibleHeight;
}
}
else if (parts[0] == "scrollTop")
{
DisplayScrollBar.Value = number;
}
this.DisplayScrollBar.Visibility = this._visibleHeight >= this._scrollHeight ? Visibility.Collapsed : Visibility.Visible;
}
private void InitializeScrollBarScript()
{
try
{
WebBrowserControl.InvokeScript(
"eval",
new[]
{
"function onScroll() { " + "var scrollPosition = document.body.scrollTop;"
+ "window.external.notify(\"scrollTop=\" + scrollPosition.toString());"
+ "window.external.notify(\"scrollHeight=\" + document.body.scrollHeight.toString());"
+ "window.external.notify(\"clientHeight=\" + document.body.clientHeight.toString()); } "
+ "window.external.notify(\"scrollHeight=\" + document.body.scrollHeight.toString());"
+ "window.external.notify(\"clientHeight=\" + document.body.clientHeight.toString()); "
+ "window.onscroll = onScroll"
});
}
catch (Exception xcp)
{
Debug.WriteLine("Exception occured while executing invoke script:");
Debug.WriteLine(xcp);
DisplayScrollBar.Visibility = Visibility.Collapsed;
}
}
#endregion
}
相關問題
- 1. Windows Phone 8 Web瀏覽器控件
- 2. Fancybox滾動條顯示在Chrome瀏覽器和Safari瀏覽器不是Firefox?
- 3. 瀏覽器控件不可滾動
- 4. 瀏覽器滾動條
- 5. 如何在windows phone 8的web瀏覽器控件中顯示htmlcontent字符串?
- 6. windows phone的瀏覽器。什麼瀏覽器使用Windows Phone?
- 7. 如何在瀏覽器窗口較小時顯示滾動條?
- 8. 如何在瀏覽器中始終顯示垂直滾動條?
- 9. 滾動條不顯示在谷歌瀏覽器
- 10. 防止在Windows Phone 7的IE瀏覽器中滾動
- 11. Chrome瀏覽器中的滾動條顯示當沒有任何滾動條時
- 12. 在web瀏覽器控件中隱藏滾動條
- 13. jQuery - 使用瀏覽器滾動條控制divs滾動
- 14. WPF瀏覽器控件滾動位置
- 15. 在Windows Phone 7上滾動WebBrowser控件
- 16. 如何在Windows Phone Web瀏覽器中顯示本地HTML?
- 17. CSS:全尺寸divs顯示瀏覽器滾動條
- 18. 當瀏覽器最大化時顯示滾動條:CSS
- 19. 瀏覽器底部滾動條不顯示
- 20. 沿滾動條滾動查看器行顯示控件
- 21. 滾動條在瀏覽器中丟失
- 22. 在Windows Phone 8 Web瀏覽器控件中使用Google Webfonts
- 23. 如何訪問C#中的瀏覽器控件的滾動條?
- 24. Silverlight控件向瀏覽器窗口添加滾動條
- 25. 使用自定義滾動條的WPF Web瀏覽器控件
- 26. 從Web瀏覽器控件中刪除滾動條
- 27. 在webkit瀏覽器上控制滾動
- 28. 允許使用鼠標滾動,但不顯示瀏覽器滾動條?
- 29. 瀏覽器滾動條移動
- 30. 的Windows手機 - 避免放置滾動瀏覽器內的Web瀏覽器控件的滾動
不是任何人對Windows Phone的開發? :( – Luke
@Coulton,aha..strange!這個平臺真的很友善,不那麼難:)很快我的小程序就會出現在市場上! ^^ – 0x49D1
您是否正在爲Windows 8開發? – Luke