【问题标题】:How do I bind HTML to a DataTemplate's WebView? [duplicate]如何将 HTML 绑定到 DataTemplate 的 WebView? [复制]
【发布时间】:2012-10-24 23:20:18
【问题描述】:

可能重复:
How to access NavigateToString property of a WebView in a ListView

我有一个项目列表,每个项目都使用 DataTemplate。在这个模板中,我有一个从 API 调用中获取的静态 HTML 的 Web 视图。 DataTemplate 类似如下:

<DataTemplate x:Name="DetailedPostTemplate">
        <Grid Height="600" Width="600">
            <Grid.RowDefinitions>
                <RowDefinition Height="2*"/>
                <RowDefinition Height="6*"/>
            </Grid.RowDefinitions>


            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="1*"/>
                    <ColumnDefinition Width="2*"/>
                </Grid.ColumnDefinitions>

                <StackPanel>
                    <TextBlock Text="{Binding Score}"/>
                    <TextBlock Text="Votes" />
                </StackPanel>

                <Grid Grid.Column="1">
                    <TextBlock Text="{Binding OwnerName}" />
                </Grid>
            </Grid>

            <!-- HTML Content Row -->

            <Grid Grid.Row="1">
                <WebView DataContext="{Binding Body}"/> <!-- What do I do HERE? -->
            </Grid>

        </Grid>
    </DataTemplate>

我所能找到的,将数据“传递”到 Webview 是使用 NavigateToString 方法,但由于我不知道列表中的项目数量,我正在使用一个模板,我不能从 C# 方面调用它。如何使用 XAML 模板将此 HTML 连接到 WebView?

【问题讨论】:

    标签: c# xaml data-binding windows-8


    【解决方案1】:

    WebView 没有支持此功能的可绑定属性。有很多人编写了附加属性,允许您绑定到 WPF 和 Silverlight WebView 控件,这些应该可以在 Windows 8 中进行一些小的更改。参见例如this solution

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-11
      • 1970-01-01
      • 1970-01-01
      • 2012-04-21
      • 1970-01-01
      • 1970-01-01
      • 2014-08-26
      • 2018-09-30
      相关资源
      最近更新 更多