페이지 매김은 위의 스택 오버플로 링크에서 설명한 것처럼 잘 작동하지만 모든 페이지는 비어 있습니다.
귀하의 프로세스에 따라 기본 인쇄 기능을 실현했습니다. webviewrenderer
에 GetWebViewBrush
메서드를 넣었습니다. 불행히도, 내 문제는 같은 문제가 발생합니다.
async Task<WebViewBrush> GetWebViewBrush(Windows.UI.Xaml.Controls.WebView webView)
{
// resize width to content
var _OriginalWidth = webView.Width;
var _WidthString = await webView.InvokeScriptAsync("eval",
new[] { "document.body.scrollWidth.toString()" });
int _ContentWidth;
if (!int.TryParse(_WidthString, out _ContentWidth))
throw new Exception(string.Format("failure/width:{0}", _WidthString));
webView.Width = _ContentWidth;
// resize height to content
var _OriginalHeight = webView.Height;
var _HeightString = await webView.InvokeScriptAsync("eval",
new[] { "document.body.scrollHeight.toString()" });
int _ContentHeight;
if (!int.TryParse(_HeightString, out _ContentHeight))
throw new Exception(string.Format("failure/height:{0}", _HeightString));
webView.Height = _ContentHeight;
// create brush
var _OriginalVisibilty = webView.Visibility;
webView.Visibility = Windows.UI.Xaml.Visibility.Visible;
var _Brush = new WebViewBrush
{
Stretch = Stretch.Uniform,
SourceName = webView.Name
};
// _Brush.SetSource(webView);
_Brush.Redraw();
// reset, return
webView.Width = _OriginalWidth;
webView.Height = _OriginalHeight;
webView.Visibility = _OriginalVisibilty;
return _Brush;
}
내가 debuging 때, 나는
webView.Name
이 값을 설정하지, 그래서 나는 customWebView에 대한 새로운
Name
특성을 한 적이 발견했다.
public static readonly BindableProperty NameProperty = BindableProperty.Create(
propertyName: "Name",
returnType: typeof(string),
declaringType: typeof(MyWebView),
defaultValue: default(string));
public string Name
{
get { return (string)GetValue(NameProperty); }
set { SetValue(NameProperty, value); }
}
}
그리고는 OnElementChanged
방법에 다음 코드와 네이티브 제어()의 Name
속성을 설정합니다.
if (e.NewElement != null)
{
Control.Name = (Element as MyWebView).Name;
Control.NavigationCompleted += Control_NavigationCompleted;
}
놀랍게도이 페이지는 더 이상 비어 있지 않습니다.
멋진! 이것은 매력처럼 작동합니다! 고마워요 :) –
@ 스 캐빈 저 : 고마워, 해냈어! –