0
好的。所以我碰到了幾個代碼示例,聲明我可以爲WPF WebBrowser控件創建一個自定義屬性,這將允許我將一串html綁定到控件進行呈現。WPF WebBrowser控件自定義屬性
下面是屬性的類(這是在一個名爲BrowserHtmlBinding.vb文件):
Public Class BrowserHtmlBinding
Private Sub New()
End Sub
Public Shared BindableSourceProperty As DependencyProperty =
DependencyProperty.RegisterAttached("Html",
GetType(String),
GetType(WebBrowser),
New UIPropertyMetadata(Nothing,
AddressOf BindableSourcePropertyChanged))
Public Shared Function GetBindableSource(obj As DependencyObject) As String
Return DirectCast(obj.GetValue(BindableSourceProperty), String)
End Function
Public Shared Sub SetBindableSource(obj As DependencyObject, value As String)
obj.SetValue(BindableSourceProperty, value)
End Sub
Public Shared Sub BindableSourcePropertyChanged(o As DependencyObject, e As DependencyPropertyChangedEventArgs)
Dim webBrowser = DirectCast(o, System.Windows.Controls.WebBrowser)
webBrowser.NavigateToString(DirectCast(e.NewValue, String))
End Sub
End Class
而XAML中:
<Window x:Class="Details"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:custom="clr-namespace:BrowserHtmlBinding"
Title="Task Details" Height="400" Width="800" Icon="/v2Desktop;component/icon.ico"
WindowStartupLocation="CenterScreen" WindowStyle="ThreeDBorderWindow"
WindowState="Maximized">
<Grid>
<WebBrowser custom:Html="<b>Hey Now</b>" />
</Grid>
</Window>
我不斷收到錯誤:錯誤1在'WebBrowser'類型中找不到'Html'屬性。
我該如何解決這個問題?它把我拉上了牆!
謝謝了! – Kevin 2012-07-13 13:44:39