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]
# 1

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
DavidJenni[MSFT] at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 2
Yeah!, It works to me.
Thanks very much Dave

cble at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified