WPF 中最糟糕的问题是什么? [英] What is the worst gotcha in WPF?

查看:26
本文介绍了WPF 中最糟糕的问题是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始给自己列一个WPF 问题"的清单:那些让我感到困扰并且我不得不写下来记住的事情,因为我每次都爱上它们......

I've started to make myself a list of "WPF gotchas": things that bug me and that I had to write down to remember because I fall for them every time....

现在,我很确定你们都曾在某个时候偶然发现过类似的情况,我希望你们分享您在这个主题上的经验:

Now, I'm pretty sure you all stumbled upon similar situations at one point, and I would like you to share your experience on the subject:

让你一直困扰的问题是什么?你觉得最讨厌的那个?

(我有几个问题似乎没有解释,也许你的提交会解释它们)

(I have a few issues that seem to be without explanation, maybe your submissions will explain them)

这是我的一些个人"陷阱(随机呈现):

Here are a few of my "personnal" gotchas (randomly presented):

  1. 即使在透明"窗口上单击时也会触发 MouseEvent控件的背景(例如标签)而不仅仅是内容(本例中的文本),控件的背景必须设置为Brushes.Transparent";而不仅仅是空"(标签的默认值)

  1. For a MouseEvent to be fired even when the click is on the "transparent" background of a control (e.g. a label) and not just on the content (the Text in this case), the control's Background has to be set to "Brushes.Transparent" and not just "null" (default value for a label)

WPF DataGridCell 的 DataContext 是单元格所属的 RowView,而不是 CellView

A WPF DataGridCell's DataContext is the RowView to whom the cell belong, not the CellView

在 ScrollViewer 内部时,Scrollbar 由 scrollviewer 本身管理(即设置 ScrollBar.Value 等属性无效)

When inside a ScrollViewer, a Scrollbar is managed by the scrollviewer itself (i.e. setting properties such as ScrollBar.Value is without effect)

Key.F10 当你按下F10"时不会被触发,而是你得到 Key.System 并且你必须去寻找 e.SystemKey 获取Key.F10

Key.F10 is not fired when you press "F10", instead you get Key.System and you have to go look for e.SystemKey to get the Key.F10

...现在你开始了.

推荐答案

  1. 始终观察输出窗口绑定错误.忽略输出窗户是眼泪的秘诀.

  1. Always watch the output window for binding errors. Ignoring the output window is a recipe for tears.

在绑定中使用 PresentationTraceOptions.TraceLevel="High" 以在调试绑定失败时获取详细的绑定信息.

Use PresentationTraceOptions.TraceLevel="High" in a binding to get verbose binding information when debugging binding failures.

制作静态、不变的资源,例如画笔 PresentationOptions:Freeze="True" 以在运行时节省资源.

Make static, unchanging resources such as brushes PresentationOptions:Freeze="True" to save resources at runtime.

使用 WPF DataGrid 作为数据网格.修改它以使其表现得像 Excel 是一件非常痛苦的事情.

Use the WPF DataGrid as a datagrid. Modifying it to behave like Excel is a massive pain in the butt.

BindingList 不能很好地与 CollectionViewSource 配合使用.改为从您的视图模型中公开 ObservableCollection.

BindingList<T> does not play well with CollectionViewSource. Expose ObservableCollection<T> from your viewmodels instead.

互联网提供了六种不同的想法来在 WPF 文本框中显示 CueBanner 文本.它们都坏了.

The internet supplies half a dozen different ideas for displaying CueBanner text in a WPF textbox. They are all broken.

这篇关于WPF 中最糟糕的问题是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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