0

我正在尝试在 Windows Store 应用程序的 FlipView 控件中打开一个网站。这是我的代码:

protected override async void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
    var template = flipView.ItemTemplate;
    var grid = (Grid)template.LoadContent();
    var webView = (WebView)grid.Children[0];

    webView.Navigate(new Uri("http://www.google.com"));
}

private void contentView_LoadCompleted_1(object sender, NavigationEventArgs e)
{
    var template = flipView.ItemTemplate;
    var grid = (Grid)template.LoadContent();
    var webView = (WebView)grid.Children[0];
    webView.Visibility = Windows.UI.Xaml.Visibility.Visible;
}

和 XAML:

  <FlipView
        x:Name="flipView"
        AutomationProperties.AutomationId="ItemsFlipView"
        AutomationProperties.Name="Item Details"
        TabIndex="1"
        Grid.RowSpan="2"
        ItemsSource="{Binding Source={StaticResource itemsViewSource}}">

        <FlipView.ItemContainerStyle>
            <Style TargetType="FlipViewItem">
                <Setter Property="Margin" Value="0,137,0,0"/>
            </Style>
        </FlipView.ItemContainerStyle>

        <FlipView.ItemTemplate>
            <DataTemplate>
                <Grid x:Name="Output">
                            <WebView x:Name="WebView1" Visibility="Collapsed" LoadCompleted="contentView_LoadCompleted_1"/>
                            <Rectangle x:Name="BlockingRect"/>
                </Grid>
            </DataTemplate>
        </FlipView.ItemTemplate>
    </FlipView>

也许有人早些时候遇到过这个问题?解决方案是什么?

4

2 回答 2

3

callisto WebViewExtension https://github.com/timheuer/callisto/wiki/WebViewExtension是我发现将 WebView 内容绑定到 FlipView 的最佳方式。

在默认用法中,WebView 项中的一些触摸(特别是点击)交互仍然存在问题,因为 FlipView 正在处理这些交互,而不是让它们落入 WebView。从而导致无法与 WebView 中的链接进行交互。使用鼠标时这不是问题,尽管点击会落入 WebView。

于 2012-12-01T20:01:17.427 回答
0

首先为您的框架控件提供唯一名称 ,而x:Name="ItemDetailPageWebView" 不是复制并粘贴在代码后面的代码后面 ı Wright Down 下面

XAML:

    <FlipView x:Name="flipView"
       AutomationProperties.AutomationId="ItemsFlipView"
       AutomationProperties.Name="Item Details"
       TabIndex="1" Grid.Row="1"
       ItemsSource="{Binding Source={StaticResource itemsViewSource}}"   
       Loaded="ItemDetailPageflipView_Loaded">
              <FlipView.ItemTemplate>
                  <DataTemplate>
                     <Grid>       
                        <ScrollViewer Margin="0,0,0,0" Style="{StaticResource HorizontalScrollViewerStyle}" >
                            <StackPanel  Orientation="Horizontal" Height="628" Width="2755">
                                  <WebView x:Name="ItemDetailPageWebView" Height="443" Margin="53,82,0,0" VerticalAlignment="Top" Width="435" />
                            </StackPanel>
                      </ScrollViewer>
                 </Grid>
            </DataTemplate>
        </FlipView.ItemTemplate>
    </FlipView>

C# :

//-----------------------------------------------------------------------------------
            public static T FindVisualChildByName<T>(DependencyObject parent, string name) where T : DependencyObject
            {
                for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
                {
                    var child = VisualTreeHelper.GetChild(parent, i);
                    string controlName = child.GetValue(Control.NameProperty) as string;
                    if (controlName == name)
                    {
                        return child as T;
                    }
                    else
                    {
                        T result = FindVisualChildByName<T>(child, name);
                        if (result != null)
                            return result;
                    }
                }
                return null;
            }

            //Here FlipView Loaded Event 
            private void ItemDetailPageflipView_Loaded(object sender, RoutedEventArgs e)
            {
                WebView ItemDetailPageWebView = FindVisualChildByName<WebView>(this.flipView, "ItemDetailPageWebView");
                ItemDetailPageWebView.Navigate(new Uri("http://www.google.com"));
            }

        //-----------------------------------------------------------------------------------

如果我有帮助,请给我一个 +,然后单击答案。快乐编码;)

于 2013-01-28T13:58:20.930 回答