2012-07-03 46 views
1

我有一個列表框,我希望列表框項目的每個項目在一個單獨的WebBrowser中顯示,我知道這聽起來像一個壞主意,但我必須這樣做。 所以這是我的部分代碼解釋什麼是我想要做的事:列表框WP7中的Webbrowser

<ListBox Margin="2,786,-14,-34" ItemsSource="{Binding comments}" DataContext="{Binding BindsDirectlyToSource=True}" Name="commentsListBox" > 
       <ListBox.ItemTemplate> 
        <DataTemplate> 
         <StackPanel Orientation="Horizontal" Margin="0,0,0,17"> 
          <StackPanel Width="311"> 
           <!--<TextBlock Text="{Binding poster_username}" TextWrapping="NoWrap" Style="{StaticResource PhoneTextSubtleStyle}" TextTrimming="WordEllipsis" Width="Auto" Foreground="White" FontFamily="Segoe WP Semibold" /> 
           <TextBlock Text="{Binding comment_text}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}" TextTrimming="WordEllipsis" MaxHeight="100" />--> 
           <phone:WebBrowser Source="{Binding comment_text}" HorizontalAlignment="Left" Margin="23,786,0,0" Name="commentsWebBrowser" VerticalAlignment="Top" Height="453" Width="440" DataContext="{Binding ElementName=commentsListBox}" Background="Black" Foreground="{x:Null}" OpacityMask="Black" Opacity="0" /> 
          </StackPanel> 
         </StackPanel> 
        </DataTemplate> 
       </ListBox.ItemTemplate> 
      </ListBox> 

如何將數據綁定之間從列表框中,將WebBrowser? 我已經看到很多人搜索了這個,但我還沒有找到答案! 非常感謝您的幫助!

回答

2

使用WebBrowser是一個壞主意。如果您需要使用HTML格式顯示某些文本,請使用MSP Toolkit(http://msptoolkit.codeplex.com/)中的HTMLTextBox或HTMLViewer

+0

非常感謝!正是我需要的! –

+0

我需要提到的是,使用MSP Toolkit是一個壞主意。 HTMLViewer拋出一個異常,我甚至可以知道如何解決它。 在'段落' –

+0

中找不到'Property Margin'我認爲這是HTML的問題,HTMLViewer不支持P上的Margin。在顯示之前將其刪除。 –