Я пытаюсь добавить столбец в свой datagrid с помощью кода follwing, но я получу крах браузера (не вижу исключения). Я добавил образец проекта здесь: http://cid-5d0909fd6cd506a0.skydrive.live.com/self.aspx/Offentlig/DependencyPropblem.zipSilverlight добавить столбец datagrid с usercontrol с помощью xamlreader
код выглядит следующим образом:
private void LoadDynamicDataColumnTemplate()
{
string xaml;
if (false)
{
// THis one does not work. Whats wrong?????????
xaml = @"<DataTemplate xmlns=""http://schemas.microsoft.com/client/2007""
xmlns:me=""clr-namespace:SilverlightApplication2"">
<me:MyUserControl Age=""{Binding Path=Age}""/>
</DataTemplate>";
}
else
{
// This runs fine!
xaml = @"<DataTemplate xmlns=""http://schemas.microsoft.com/client/2007""
xmlns:me=""clr-namespace:SilverlightApplication2"">
<Button Content=""{Binding Path=Age}""/>
</DataTemplate>";
}
DataGridTemplateColumn tc = new DataGridTemplateColumn();
tc.CellTemplate = (DataTemplate)XamlReader.Load(xaml);
tc.Header = "Dynamic";
MyDataGrid.Columns.Add(tc);
}
Моя DataGrid определяется следующим образом:
<data:DataGrid x:Name="MyDataGrid" ItemsSource="{Binding Path=Rows}" AutoGenerateColumns="False">
<data:DataGrid.Columns>
<data:DataGridTextColumn Binding="{Binding Path=Name}" Header="Name"></data:DataGridTextColumn>
<data:DataGridTemplateColumn Header="Static">
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<me:MyUserControl Age="{Binding Path=Age}"/>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
</data:DataGrid.Columns>
</data:DataGrid>
И мой UserControl так:
<UserControl x:Class="SilverlightApplication2.MyUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<Grid x:Name="LayoutRoot" Background="Red">
<Button Content="{Binding Age}" Click="Button_Click"/>
</Grid>
Любая помощь будет замечательной!
I'was используя бег с SL 3 беты, но после его удаления, и reinnstalling инструментов мне удалось получить исключение:
Sys.InvalidOperationException: ManagedRuntimeError ошибка # 4004 в управлении 'Xaml1': Система. 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: System.Windows.Markup.XamlParseException: System.Windows.Markup.XamlParseException: System.Windows.Markup.XamlParseException: AG_E_UNKNOWN_ERROR [Строка: 1 позиция: 162] на MS.Internal .XcpImports.MethodEx (IntPtr PTR, имя Строка, CValue [] cvData) на MS.Internal.XcpImports.MethodEx (DependencyObject OBJ, имя String) на MS.Internal.XcpImports.DataTemplate_LoadContent (шаблон DataTemplate) в System.Windows .DataTemplate.LoadContent() в System.Windows.Controls.DataGrid.PopulateCellContent (Boolean forceTemplating, булевой isCellEdited, DataGridColumn DataGridColumn, DataGridRow dataGridRow, dataGridCell dataGridCell) в System.Windows.Controls.DataGrid.AddNewCellPrivate (DataGridRow строка, столбец DataGridColumn) на System.Windows.Controls.DataGrid.CompleteCellsCollection (dataGridRow dataGridRow) в System.Windows.Controls.DataGrid.GenerateRow (Int32 RowIndex) в System.Windows.Controls.DataGrid.GetEdgedExactRowHeight (Int3 2 RowIndex) на System.Windows.Controls.DataGrid.UpdateDisplayedRows (Int32 newFirstDisplayedRowIndex, Double displayHeight) на System.Windows.Controls.DataGrid.ComputeScrollBarsLayout() в System.Windows.Controls.DataGrid.MeasureOverride (размер availableSize) в System.Windows.FrameworkElement.MeasureOverride (IntPtr nativeTarget, Single inWidth, Single inHeight, Single & outWidth, Single & outHeight) [Line: 0 Position: 0] at MS.Internal.XcpImports.MethodEx (IntPtr ptr, String name, CValue [] cvData) в MS.Internal.XcpImports.MethodEx (DependencyObject OBJ, имя String) в MS.Internal.XcpImports.DataTemplate_LoadContent (шаблон DataTemplate)
Но все еще не работает код. Теперь я использую 2.0.40115.0 и VSTS 2008 Dev ed.
Любые идеи?
С уважением Larsi
Я работаю на VSTS 2008 SP1, с установленной версией SL 3.0 ..... – 2009-03-23 19:34:25
Хорошо, если у меня есть время, я попробую сегодня на SL 3.0, у меня его нет. –