[英]the type DataGrid doesn't support direct Content
I am xaml and c# beginner i am across a situation in silverlight application that i got this error i am trying to create columns using xaml (i dont have to use c# or anything dynamic). 我是xaml和C#初学者,我遇到了Silverlight应用程序中的一种情况,遇到此错误,我试图使用xaml创建列(我不必使用c#或任何动态的东西)。
here is my code: 这是我的代码:
<UserControl x:Class="DEV_CENTER.ProgramGrid"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
xmlns:dataprimitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"
xmlns:vm="clr-namespace:ViewModel;assembly=ViewModel"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<UserControl.Resources>
<vm:ProgramViewModel x:Key="ProgramViewModel"/>
</UserControl.Resources>
<data:DataGrid x:Name="gridPrograms"
Grid.Row="0"
AutoGenerateColumns="False"
ItemsSource="{Binding Path=ListPrograms }"
IsReadOnly="True"
DataContext="{StaticResource ProgramViewModel}">
<data:DataGridTextColumn Header="c1"
Binding="{Binding Version}"
Width="2*"/>
<data:DataGridTextColumn Header="c2"
Binding="{Binding Live}"
Width="2*"/>
<data:DataGridTextColumn Header="c3"
Binding="{Binding DateCreation}"
Width="2*"/>
<data:DataGridTextColumn Header="..." Width="*"/>
</data:DataGrid.Columns>
</data:DataGrid>
</UserControl>
And i get error : the type DataGrid doesn't support direct Content
而且我得到错误:
the type DataGrid doesn't support direct Content
EDIT:The problem was due to missing <data:DataGrid.Columns>
that is solved but second problem is how to bind the column ? 编辑:该问题是由于缺少解决的
<data:DataGrid.Columns>
但第二个问题是如何绑定列? Could someone please give me the solution ? 有人可以给我解决方案吗? I mean i have to create columns using xaml only (not c#) and bind them.
我的意思是我必须仅使用xaml创建列(而不使用c#)并将其绑定。 How to do that ?
怎么做 ? thanks
谢谢
The message means you are not allowed to put anything between the opening and closing tags of the DataGrid
as long as you are not "addressing" a DataGrid
property, you are missing the opening tag <data:DataGrid.Columns>
: 该消息表示,只要不“寻址”
DataGrid
属性,并且缺少起始标记<data:DataGrid.Columns>
,就不允许在DataGrid
起始标记和结束标记之间放置任何内容:
<data:DataGrid ...>
<data:DataGrid.Columns>
...
</data:DataGrid.Columns>
</data:DataGrid>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.