如何從數據表中設置datagrid控件值?datatable作爲wpf中datagrid的項目源
我用這個源
public static readonly DependencyProperty ObjDataTableDefaultViewProperty = DependencyProperty.Register("ObjDataTableDefaultView", typeof(System.Data.DataView), typeof(Window1), new FrameworkPropertyMetadata());
public System.Data.DataView ObjDataTableDefaultView
{
get { return (System.Data.DataView)GetValue(ObjDataTableDefaultViewProperty); }
set { SetValue(ObjDataTableDefaultViewProperty, value); }
}
private void CreateObjDataTable()
{
try
{
ObjDataTableDefaultView = table.DefaultView;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
但它已經得到了一個錯誤信息,然後程序停止,
發生的類型 「System.Windows.Markup.XamlParseException」第一次機會異常in PresentationFramework.dll
附加信息:無法創建在 程序集中定義的'Window1'實例'ReadSky,Version = 1.0.0.0,Culture = neutral, PublicKeyToken = null'。 調用的目標已拋出異常。錯誤標記文件「Window1.xaml」 1個線9號位置
My XAML
<Window x:Class="ReadSky.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="296" Width="738" xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit">
<Grid>
<my:DataGrid AutoGenerateColumns="False" Margin="36,30,39,90" Name="gridCtrl" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" IsReadOnly="True" RowBackground="Gray" AlternatingRowBackground="White" ItemsSource="{Binding ObjDataTableDefaultView, ElementName=uc, Mode=OneWay}"/>
</Grid>
</Window>
請你可以發表你的XAML – 2012-03-07 14:54:34