简体   繁体   English

DataGrid类型不支持直接Content

[英]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.

相关问题 RowDetailsTemplate不会自动调整大小-Silverlight DataGrid - RowDetailsTemplate doesn't autosize back - Silverlight DataGrid Datagrid不会刷新已更改的数据 - Datagrid doesn't refresh on changed data 我的dataGrid无法清除并且无法刷新 - My dataGrid doesn't clear and doesn't refresh Silverlight Canvas不支持KeyDown? - Silverlight Canvas doesn't support KeyDown? 为什么Silverlight不提供IME支持? - Why doesn't Silverlight provide IME support? combobox selectionchanged事件不会在Silverlight mvvm中更新datagrid - combobox selectionchanged event doesn't update datagrid in Silverlight mvvm 自定义实体对象属性不会在Silverlight DataGrid中更新 - Custom Entity object property doesn't update in Silverlight DataGrid 获取错误:合同需要Duplex,但Binding&#39;BasicHttpBinding&#39;不支持它,或者没有正确配置以支持它 - Getting an error: Contract requires Duplex, but Binding 'BasicHttpBinding' doesn't support it or isn't configured properly to support it 您的浏览器不支持Flash,Silverlight或HTML5 - Your browser doesn't have Flash, Silverlight or HTML5 support Chrome不再支持Silverlight吗? 如何解决呢? - Chrome doesn't support silverlight anymore? How to solve this?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM