2013-08-20 2 views
0

У меня есть сложный тип, как показано нижеBind несколько свойств к нескольким атрибутов текстового поля в silverlight4

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

} 

им список выше 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 parse, как показано ниже.

--------------------------- 
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}" 

Вы не можете связать х: Имя собственности (источники here и here). Не могли бы вы объяснить, чего вы хотите добиться, связав это свойство? Возможно, это можно сделать по-другому.

Смежные вопросы