Silverlight: System.ArgumentException with DataGridTemplateColumns and UserControls with x:Name
Posted by Ben G on November 4, 2009
I had a UserControl that specified an x:Name value like this:
<UserControl x:Class="CatManagement.UI.TestControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300" x:Name="Me">
I assigned an x:Name because I was wanting to bind certain UI elements to custom properties defined on my user control. However, this caused a problem when I used this user control in a DataGridTemplateColumn like this:
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<local:AssignUserControl DataContext="{Binding}" />
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
The problem was that the following exception was thrown whenever a second DataGrid row was inserted: