【问题标题】:UWP: `webview` contents cut off if window is resizedUWP:如果调整窗口大小,“webview”内容会被切断
【发布时间】:2018-11-22 16:40:42
【问题描述】:

我想用窗口调整 webview 的大小。 但是,当我减小窗口大小时,webview 会被切断。 (当我增大窗口大小时,它看起来很正常。)

    <Grid>
        <WebView x:Name="m_WebView" HorizontalAlignment="Left" Height="350" Margin="0,0,0,0" VerticalAlignment="Top" Width="568" ScriptNotify="m_WebView_ScriptNotify" NavigationCompleted="m_WebView_OnNavigationCompleted" x:FieldModifier="public"/>
        <ProgressRing x:Name="workingProgressRing" HorizontalAlignment="Center" VerticalAlignment="Center" Width="50" Height="50"/>

    </Grid>

        private void Page_onSizeChanged2(object sender, SizeChangedEventArgs e)
        {

            double widthRatio = e.NewSize.Width / (double)568;
            double heightRatio = e.NewSize.Height / (double)320;
            double newRatio = widthRatio < heightRatio ? widthRatio : heightRatio;
            double newWidth = 568 * newRatio;
            double newHeight = 320 * newRatio;

            m_WebView.RenderTransform = new CompositeTransform { ScaleX = newRatio, ScaleY = newRatio };

            ((CompositeTransform)m_WebView.RenderTransform).TranslateX = -(newWidth - 568 * widthRatio) / 2;
            ((CompositeTransform)m_WebView.RenderTransform).TranslateY = -(newHeight - 320 * heightRatio) / 2;


        }

Normal window picture.

Cut off webview picture.

【问题讨论】:

  • 如何一起缩小尺寸?帮帮我..

标签: windows visual-studio c#-4.0 uwp


【解决方案1】:

在 UWP 中调整控件大小的正确方法是根据布局自动缩放,而不是直接硬编码 WidthHeight 值。

在您的情况下,您可以删除WidthHeight 属性,将HorizontalAlignmentVerticalAlignment 设置为Stretch,并让WebViewGrid 一起缩放。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-20
    • 2013-07-10
    • 1970-01-01
    • 2012-05-08
    • 2012-07-24
    • 2012-07-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多