You do not need DataContext={Binding} , as this is equivalent to DataContext = DataContext .
However, you do not have enough type information. Bindings use reflection to resolve property paths; however, when encoding, you need to know the type of object returned by the DataContext .
If you can be sure of this, it will be simple: -
myWebBrowser.NavigateToString(((MyType)DataContext).MyHTMLString);
If you cannot be sure of the type and / or cannot convince those who control the host of your controls in order to provide at least a certain interface with known members, then you may need to resort to reflection.
Use the snap system to make a reflection for you
An alternative if you cannot know the type is just the name of the property: -
public string HTMLString { get { return (string)GetValue(HTMLStringProperty); } set { SetValue(HTMLStringProperty, value); } } public static DependencyProperty HTMLStringPropery = DependencyProperty.Register( "HTMLString", typeof(string), typeof(SomeControl), null);
Now, if you are sure that you know the name of the property you want to bind, you can configure the code binding in your control constructor: -
SetBinding(HTMLStringProperty, new Binding("MyHTMLString"));
With this in place, your code will look like this: -
myWebBrowser.NavigateToString(HTMLString);
Alternatively, you can attach this new property of your control to Xaml's liability: -
<DataTemplate x:Key="AnImportantIdentifierUsedByTheHostApp"> <MyControls:SomeControl HTMLString="{Binding MyHTMLString}" /> </DataTemplate>