疑问:WPFToolkit中的DataGrid数据列为何会意外丢失?

我有一个工程,要多次使用数据表格,每次使用的数据集的列可能不同,那么我就想到写一个UserControl公共控件来使用,将经常对数据集操作的通用的动作放到里面。UserControl中,DataGrid的具体定义如下:

 

ContractedBlock.gif ExpandedBlockStart.gif 代码
 
   
1 < dg:DataGrid DockPanel.Dock ="Top" Name ="dgData" ItemsSource =" {Binding} " BorderThickness ="0" AlternationCount ="2" AutoGenerateColumns ="True" ColumnHeaderStyle =" {StaticResource dgHeaderStyle} "
2 RowStyle =" {StaticResource dgRowStyle} " CellStyle =" {StaticResource dgCellStyle} " SelectionMode ="Extended"
3 SelectionUnit ="FullRow" GridLinesVisibility ="All" VerticalGridLinesBrush ="DarkGray" >


然后在工程里使用这个包含DataGrid的定义好的UserControl,具体实现是使用C#代码创建的,没有在xaml文件中实现(其实效果一样),运行程序发现,DataGrid只可以正常呈现数据集一次,只要我把鼠标放到DataGrid的边框左边或数据单元中点击一下,数据列马上就消失了,数据也看不到了,我用一个信息框打开看到Items.Count>0,Columns.Count=0!

操作截图如下:

1)正常打开数据。

2010060720522513.png

2)打开数据之后鼠标在UserControl的DataGrid中点击。

2010060720515551.png

注意:不能点击DataGrid那个左边框(类似RowHeader),不然程序会崩溃,出现致命错误。错误信息如下:

未处理 System.ArgumentOutOfRangeException
  Message="The given DisplayIndex is out of range.  DisplayIndex must be greater than or equal to 0 and less than Columns.Count.\r\n参数名: displayIndex\r\n实际值是 0。"
  Source="WPFToolkit"
  ParamName="displayIndex"
  StackTrace:
       在 Microsoft.Windows.Controls.DataGrid.ColumnFromDisplayIndex(Int32 displayIndex) 位置 C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\DataGrid\Microsoft\Windows\Controls\DataGrid.cs:行号 354

。。。。

很郁闷!

3)然后数据列不见了,点击上方的Button按钮查看没有Column了。

2010060720513948.png

4)运行时动态创建的包含了DataGrid的UserControl就可以正常显示操作数据。

2010060720511285.png

5)在另外的程序中单独使用这个UserControl也是正常的。

2010060720505831.png

 

请各位精通WPF的高手帮忙!(程序方面,我使用了RibbonControl和WPFToolkit两个控件包,程序主窗口基承自RibbonWindow,但反复测试过,这个问题与窗体是否为标准Window无关,而且与DataGrid中是否使用了Style也无关。)

(程序代码在这里:http://files.cnblogs.com/glowworm/GWControlLib%2bSQLEditor.rar

谢谢!

转载于:https://www.cnblogs.com/glowworm/archive/2010/06/07/1753466.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值