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