在wpf datagrid中绑定数据表时抛出异常 [英] Throw exception while binding datatable in wpf datagrid

查看:81
本文介绍了在wpf datagrid中绑定数据表时抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它在一个简单的DataGridControl对象中显示报告的结果。



在wpf datagrid中绑定数据表时抛出异常

I have an application that displays the results from reports in a simple DataGridControl object.

its Throw exception while binding datatable in wpf datagrid

'The invocation of the constructor on type 'WpfApplication1.MainWindow' that matches the specified binding constraints threw an exception.' Line number '3' and line position '9'.



我的设计页面


My design page

<window x:class="WpfApplication1.MainWindow" xmlns:x="#unknown">
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <grid>
        <datagrid autogeneratecolumns="False" height="200" itemssource="{Binding Path=Collection}" horizontalalignment="Left" margin="76,11,0,0" name="dataGrid1" verticalalignment="Top" width="261">
            <datagridtextcolumn header="RowNumber" binding="{Binding Path=RowNumber}" />
        </datagrid>
    </grid>
</window>



代码落后


Code behind

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            DataTable Collection = new DataTable();
            DataRow dr = null;
            Collection.Columns.Add(new DataColumn("RowNumber", typeof(string)));
            dr = Collection.NewRow();
            dr["RowNumber"] = "test";
            Collection.Rows.Add(dr);
            dataGrid1.ItemsSource = Collection.AsDataView();
        }
    }
}



这里错了

提前致谢


Whats wrong here
Thanks in advance

推荐答案

错字?你有一个>在第一行结尾...



Typo ?? you have a ">" at the end of first line ...

<window x:class="WpfApplication1.MainWindow" xmlns:x="#unknown">
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">


这篇关于在wpf datagrid中绑定数据表时抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆