Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用Python填充WPF数据网格_Python_.net_Wpf_Data Binding_Python.net - Fatal编程技术网

无法使用Python填充WPF数据网格

无法使用Python填充WPF数据网格,python,.net,wpf,data-binding,python.net,Python,.net,Wpf,Data Binding,Python.net,我在使用Python.NET将数据绑定到WPF数据网格时遇到问题 代码如下所示,我尝试了三种不同的数据绑定方法——每种方法都失败,错误消息作为注释包含在下面的代码中 如果我不尝试添加数据,datagarid将正确显示并带有标题。但我无法用任何数据填充网格 任何帮助都将得到感激 道格 我看不到您正在创建数据表实例 DataTable data_table = CreateDataTable(); 再试试这个 myDataGrid.ItemsSource = data_table.DefaultV

我在使用Python.NET将数据绑定到WPF数据网格时遇到问题

代码如下所示,我尝试了三种不同的数据绑定方法——每种方法都失败,错误消息作为注释包含在下面的代码中

如果我不尝试添加数据,datagarid将正确显示并带有标题。但我无法用任何数据填充网格

任何帮助都将得到感激

道格


我看不到您正在创建数据表实例

DataTable data_table = CreateDataTable();
再试试这个

myDataGrid.ItemsSource = data_table.DefaultView;
在XAML中

<DataGrid Name="myDataGrid" ItemsSource="{Binding}">

我看不到您正在创建数据表实例

DataTable data_table = CreateDataTable();
再试试这个

myDataGrid.ItemsSource = data_table.DefaultView;
在XAML中

<DataGrid Name="myDataGrid" ItemsSource="{Binding}">

我明白了-我对数据表的导入错误。 改变

然后接受了哈马斯的建议,改变了

"myDataGrid.DataContext = data_table.DefaultView" 

谢谢你,哈马斯

好的

我明白了-我对数据表的导入错误。 改变

然后接受了哈马斯的建议,改变了

"myDataGrid.DataContext = data_table.DefaultView" 


谢谢你,哈马斯

为了完整起见,这里是工作代码。 注意,通过使用DataTable,我能够删除所有手动列、标题和绑定设置

import clr

#.NET references
import System.Windows.Controls as WPFControls
import System.Data as WPFData

def getCustomToolPropertyContent():

   #Create a Grid
   my_Grid = WPFControls.Grid()

   #Add 1 Row and One Column
   my_Grid.RowDefinitions.Add(WPFControls.RowDefinition())
   my_Grid.ColumnDefinitions.Add(WPFControls.ColumnDefinition())

   # Create a DataGrid
   myDataGrid = WPFControls.DataGrid()

# Data table approach....  
   #Create a DataTable
   data_table = WPFData.DataTable("MyDataTable")
   data_table.Columns.Add("ID")
   data_table.Columns.Add("Title")
   data_table.Columns.Add("Content")

   #Add data 
   data_table.Rows.Add("Andre", "Piratas", "1973")
   data_table.Rows.Add("Andres", "Piratass", "1973s")

   myDataGrid.ItemsSource = data_table.DefaultView     

   # Position the DataGrid in the first row, column of the Grid
   WPFControls.Grid.SetRow(myDataGrid, 0)
   WPFControls.Grid.SetColumn(myDataGrid, 0)

   #Add the DataGrid to the Grid 
   my_Grid.Children.Add(myDataGrid)

   # Return the Grid   
   return my_Grid

为了完整起见,这里是工作代码。 注意,通过使用DataTable,我能够删除所有手动列、标题和绑定设置

import clr

#.NET references
import System.Windows.Controls as WPFControls
import System.Data as WPFData

def getCustomToolPropertyContent():

   #Create a Grid
   my_Grid = WPFControls.Grid()

   #Add 1 Row and One Column
   my_Grid.RowDefinitions.Add(WPFControls.RowDefinition())
   my_Grid.ColumnDefinitions.Add(WPFControls.ColumnDefinition())

   # Create a DataGrid
   myDataGrid = WPFControls.DataGrid()

# Data table approach....  
   #Create a DataTable
   data_table = WPFData.DataTable("MyDataTable")
   data_table.Columns.Add("ID")
   data_table.Columns.Add("Title")
   data_table.Columns.Add("Content")

   #Add data 
   data_table.Rows.Add("Andre", "Piratas", "1973")
   data_table.Rows.Add("Andres", "Piratass", "1973s")

   myDataGrid.ItemsSource = data_table.DefaultView     

   # Position the DataGrid in the first row, column of the Grid
   WPFControls.Grid.SetRow(myDataGrid, 0)
   WPFControls.Grid.SetColumn(myDataGrid, 0)

   #Add the DataGrid to the Grid 
   my_Grid.Children.Add(myDataGrid)

   # Return the Grid   
   return my_Grid

这是Python,因此行data_table=WPFBindings.DataTableMyDataTable创建数据表。我试着从DataSource切换到ItemsSource-相同的错误属性error:DataTable请阅读此内容。它肯定会很好地帮助您!很高兴你得到了它:一个关于堆栈溢出的感谢被接受为答案或向上投票:stay blessedThis是Python,因此行data_table=WPFBindings.DataTableMyDataTable创建了DataTable。我试着从DataSource切换到ItemsSource-相同的错误属性error:DataTable请阅读此内容。它肯定会很好地帮助您!很高兴你得到了它:堆栈溢出上的一个感谢被接受为答案或向上投票:保持幸福