2013-08-20 74 views
0

我有一个复杂的类型,如下绑定多个属性到文本框的多个属性在silverlight4

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

} 

IM结合上面的complexType的列表提供给数据网格所以

<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 
--------------------------- 
+0

你想要的结果是什么?首先x:Name =“{Binding Id}”在绑定中无效 –

回答

0

你的问题是,在这一部分:

x:Name="{Binding Id}" 

您可以在x不绑定:Name属性(来源herehere)。你能解释一下你想通过绑定这个属性来达到什么目的吗?也许可以用其他方式完成。