问题是那
WebBrowser.Source不是一个
DependencyProperty。一种解决方法是使用某种
AttachedProperty魔术来启用此功能。
public static class WebBrowserUtility{ public static readonly DependencyProperty BindableSourceProperty = DependencyProperty.RegisterAttached("BindableSource", typeof(string), typeof(WebBrowserUtility), new UIPropertymetadata(null, BindableSourcePropertyChanged)); public static string GetBindableSource(DependencyObject obj) { return (string) obj.GetValue(BindableSourceProperty); } public static void SetBindableSource(DependencyObject obj, string value) { obj.SetValue(BindableSourceProperty, value); } public static void BindableSourcePropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) { WebBrowser browser = o as WebBrowser; if (browser != null) { string uri = e.NewValue as string; browser.Source = !String.IsNullOrEmpty(uri) ? new Uri(uri) : null; } }}然后在您的xaml中执行以下操作:
<WebBrowser ns:WebBrowserUtility.BindableSource="{Binding WebAddress}"/>


