Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing a custom attached property with a binding
    primarykey
    data
    text
    <p>I was looking at <a href="https://stackoverflow.com/questions/263551/databind-the-source-property-of-the-webbrowser-in-wpf">this question</a>, but I don't understand how to actually USE the created AttachedProperty. The problem is trying to have a binding on the source of the WebBrowser control.</p> <p>The code there looks like:</p> <pre><code>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 = uri != null ? new Uri(uri) : null; } } } </code></pre> <p>and </p> <pre class="lang-xml prettyprint-override"><code>&lt;WebBrowser ns:WebBrowserUtility.BindableSource="{Binding WebAddress}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled" Width="300" Height="200" /&gt; </code></pre> <p>The WebAddress, what is that exactly? This is my understanding (which is probably wrong):</p> <ul> <li>There's an AttachedProperty that can be attached to any object, and in this particular case, it is basically just attaching a property called BindableSource which is of type String.</li> <li><p>When we have the "{Binding WebAddress}" it means that in some c# code somewhere that handles this .xaml file there's something that looks like:</p> <pre><code>public String WebAddress { // get and set here? not sure } </code></pre></li> <li>And to take advantage of the property changed, I can called RaisedPropertyChanged and it will fire that static method up there?</li> </ul> <p>Even when I look at it, it doesn't seem right, but I can't find anything online to help me.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload