C#WPF tabControl中的问题控制数据绑定 [英] Problem in C# WPF tabControl Data Binding

查看:184
本文介绍了C#WPF tabControl中的问题控制数据绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好
我已使用C#WPF编写程序.
该程序允许用户制作一些选项卡.
每个选项卡中都有一些项目.
用户可以添加/删除任何选项卡或项目.
每次用户关闭程序时,当前的选项卡和项目都将保存在文件中.
选项卡和项目通过 TabpageItem InfoItem 类进行绑定.

程序启动时,用户会看到选项卡.首先,没有选择任何选项卡.如果用户选择任何选项卡,则根据数据绑定正确显示该选项卡.
1. /files/AhkLFHfER7OmiRFtXfjKLWEv82VTtXeLPOpFzzfQtAMwLPRej2*H2euYNyZNZ057RDdB8mmFp1Uh5tOADwObnEvgXHdSJ8ag/Untitled.jpg"target =" _ blank"title =" <<
问题是当用户选择另一个选项卡时.目前,项目无法正确显示(选项卡内的用户控件为空白)
我已经上传了程序:
http://www.megaupload.com/?d=FL6BB1YK [

Hello
I have used C# WPF to write a program.
This program allows the user to make some tabs.
Each tab has some items inside.
The user can add/remove any tab or item.
Each time the user closes the program, the current tabs and items will be saved inside a file.
Tabs and items are binded with TabpageItem and InfoItem classes.

When the program starts, the user sees the tabs. At first no tab is selected. If user selects any tab, the tab is shown correctly according to the data binding.
Image 1 (Desired)[^]

The problem is when the user selects another tab. At this time, items are not shown correctly(the user control inside the tab is blank)
Image 2 (Undesired)[^]

I have uploaded the program:
http://www.megaupload.com/?d=FL6BB1YK[^]

Please have a look at it. If you have a suggestion, please test it on the program in advance.
Any helpful idea is appreciated.
best regards.

推荐答案

我不知道为什么人们还没有回答您的问题,也许他们遇到了与您的项目同样的挑战.您的代码挤满了代码,执行起来并不容易,但是从我注意到的情况来看,我认为问题出在您将用户控件设置为TabControl的Datatemplate以及创建新选项卡的方式.我之所以这样说是因为,如果删除最后一个选项卡,则上一个选项卡上的内容会显示回来;如果您尝试对最后一个选项卡进行操作,则问题是相同的.尝试再次重新访问UserControl.


建议:
I don''t know why people have not responded to your questions yet, maybe they encountered the same challenges I had with your project. Your code is jam-packed and it''s not easy to step through but from what I noticed, I think the problem comes from the User Control that you set as the Datatemplate for the TabControl and also with the way new tabs were created. I said this because if you delete the last tab, the content on the previous tab shows back, if you tried that to the last tab, the issue is the same. Try to revisit the UserControl again.


Suggestions:

  1. 尝试将UserControl中所有控件的属性绑定到一个类上
  2. 然后为您创建的每个新标签页创建该类的新对象,以便每个标签页都可以保留其内容.
  3. li>

  1. Try to bind the properties of all controls in that UserControl to a class
  2. Then create a new object of that class for each new tabs that you create so that each tab can retain its content.


注意:


Note:


  1. 我本来可以提供进一步的帮助,但是您的解决方案在UserControl中也包含一些NullReferenceException.
  2. 我还应该指出,我检查了您在CodeProject上的活动,发现您不赞成这样做有投票权的人,即使他们试图提供帮助.如果继续这种方式,您可能无法在这里获得必须的帮助(我的意思是在CP上).如果您认为我提供的解决方案不够清晰,请问...没有必要投票.


这篇关于C#WPF tabControl中的问题控制数据绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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