Как данная ссылка на ответ является в настоящее время доступна только на Веб-архив, я продублировал ответ, который был дан там:
public static class DataBinder
{
private static readonly DependencyProperty DummyProperty = DependencyProperty.RegisterAttached(
"Dummy",
typeof(Object),
typeof(DependencyObject),
new UIPropertyMetadata(null));
public static object Eval(object container, string expression)
{
var binding = new Binding(expression) { Source = container };
return binding.Eval();
}
public static object Eval(this Binding binding, DependencyObject dependencyObject = null)
{
dependencyObject = dependencyObject ?? new DependencyObject();
BindingOperations.SetBinding(dependencyObject, DummyProperty, binding);
return dependencyObject.GetValue(DummyProperty);
}
}
Пример:
public partial class PropertyPathParserDemo : Window
{
public PropertyPathParserDemo()
{
InitializeComponent();
Foo foo = new Foo() { Bar = new Bar() { Value = "Value" } };
this.Content = DataBinder.Eval(foo, "Bar.Value");
}
public class Foo
{
public Bar Bar
{
get;
set;
}
}
public class Bar
{
public string Value
{
get;
set;
}
}
}
Я думаю, что это сообщение отвечает на ваш вопрос: [http://social.expression.microsoft.com/Forums/en-US/w пф/резьба/315d2442-b978-4e5f-89cd-1004a51f390d /] (http://web.archive.org/web/20120202063115/http://social.expression.microsoft.com/Forums/en-US/wpf/ резьба/315d2442-b978-4e5f-89cd-1004a51f390d) – sacha