0

我有一个复杂的类型如下

 public class EmployeessList
{
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string LatName { get; set; }

}

我将上述复杂类型的列表绑定到数据网格,所以

    <sdk:DataGridTemplateColumn Header="Value" Width="150*" >
                                                                    <sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel VerticalAlignment="Center">
<TextBox x:Name="{Binding Id}"  Text="{Binding FirstName,Mode=TwoWay}"   />
</StackPanel>
</DataTemplate>
                                                                    </sdk:DataGridTemplateColumn.CellTemplate>

如上所述,我想将多个属性绑定到文本框的多个属性,例如

当我运行此代码时,它给出了错误 xaml 解析异常,如下所示。

---------------------------
Message from webpage
---------------------------
Unhandled Error in Silverlight Application 
Code: 4004    
Category: ManagedRuntimeError       
Message: System.Windows.Markup.XamlParseException: System.Windows.Markup.XamlParseException: System.Windows.Markup.XamlParseException: System.Windows.Markup.XamlParseException: System.Windows.Markup.XamlParseException: System.Windows.Markup.XamlParseException: System.Windows.Markup.XamlParseException: System.Windows.Markup.XamlParseException: The name already exists in the tree: . [Line: 0 Position: 0] ---> System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.

   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)

   at System.Windows.ResourceManagerWrapper.GetResourceForUri(Uri xamlUri, Type componentType)

   --- End of inner exception stack trace ---

   at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)

   at MS.Internal.XcpImports.MethodEx(DependencyObject obj, String name)

   at MS.Internal.XcpImports.DataTemplate_LoadContent(DataTemplate template)

   at System.Windows.DataTemplate.LoadContent()

   at System.Windows.Controls.DataGridTemplateColumn.GenerateElement(DataGridCell cell, Object dataItem)

   at System.Windows.Controls.DataGridColumn.GenerateElementInternal(DataGridCell cell, Object dataItem)

   at System.Windows.Controls.DataGrid.PopulateCellContent(Boolean isCellEdited, DataGridColumn dataGridColumn, DataGridRow dataGridRow, DataGridCell dataGridCell)

   at System.Windows.Controls.DataGrid.AddNewCellPrivate(DataGridRow row, DataGridColumn column)

   at System.Windows.Controls.DataGrid.CompleteCellsCollection(DataGridRow dataGridRow)

   at System.Windows.Controls.DataGrid.GenerateRow(Int32 rowIndex, Int32 slot, Object dataContext)

   at System.Windows.Controls.DataGrid.GenerateRow(Int32 rowIndex, Int32 slot)

   at System.Windows.Controls.DataGrid.InsertDisplayedElement(Int32 slot, Boolean updateSlotInformation)

   at System.Windows.Controls.DataGrid.GetExactSlot…
---------------------------
OK   
---------------------------
4

1 回答 1

0

你的问题出在这部分:

x:Name="{Binding Id}"

您不能绑定 x:Name 属性(来源herehere)。你能解释一下你想通过绑定那个属性来实现什么吗?也许它可以通过其他方式完成。

于 2013-08-20T15:14:53.653 回答