Ambiguous Match Exception during WPF Databinding
Hello,
The class I am trying to bind extends from another with virtual properties. It looks like WPF databinding engine uses reflection to find the properties but it does not take the last implemented. It throws an AmbiguousMatchException. It is described in this post:
http://www.sitechno.com/Blog/AmbiguousMatchExceptionDuringWPFBinding.aspx
I can't change my classes so I wonder if there is any way to solve this issue.
Thanks
[447 byte] By [
cble] at [2008-1-10]
interesting, I couldn't get to repro this exception on neither NetFX3 gold bits nor on the current Orcas candidate bits. Anyhow, there is a way to disambiguate or even coerce to either use the base or derived class' property implementation by "type-casting" the Binding's Path:
<Window x:Class="RedefinedProperty.Window1" ......
xmlns:loc="clr-namespace:RedefinedProperty">
...
<TextBlock Text="{Binding Path=(loc:MyData.MyProperty)}" />
Using the following data object and DataContext setup
namespace RedefinedProperty
{
public class MyData
{
public virtual string MyProperty
{ get { return "value of base class"; } }
}
public class MySpecificData<T> : MyData
{
public
string
MyProperty {
get
{ return
"derived class value"; } } }
}
public
partial
class
Window1 : Window {
private
void
OnLoaded(object
sender, RoutedEventArgs e) {
this
.DataContext = new
MySpecificData<int
>(); }
}
.Dave