当数据绑定 PivotControl 来自相似对象时,数据绑定 PivotControl 会跳过它们 [WP7]

发布于 2025-01-03 09:12:27 字数 685 浏览 1 评论 0原文

我有一个带绑定的 PivotControl。一切都很顺利,直到我添加了一个枢轴,两个具有相同标题的枢轴,我们称它们为 C 和 C',以及 A 和 B 两个不同的枢轴,顺序如下:AC'BC。现在,当我尝试从 B 转到 C 时,一切都正常。但是当我从 A 转到 C 时,它做了奇怪的事情:不动,移动标题但不移动内容......很奇怪。

我调试了 PivotControl 中的 SelectionChanged 事件,它甚至是最奇怪的。它被调用两次:第一次,从 C 到另一个枢轴的转换,然后另一个包含正确转换的调用,从 A 到 C。

我已经尝试了所有方法。数据绑定是一个结构列表,如下所示:

struct Resource
{
   public someenum Type;
   public string Data;
   public string Identifier { get {...} set {...} }
   public UserToken User;
}

数据透视表的标题由 IValueConverter 设置,它采用字符串标识符(它是类型、数据和用户的函数)作为参数。我更改了它以使标题始终不同,但它仍然不起作用。例如,当类型和数据相同时,尽管标识符和用户不同,但也会出现错误。

我为 Resource 和 UserToken 编写了运算符 == 和 !=。他们表现得像他们应该的那样,但仍然进行这种奇怪的转变。

I have a PivotControl with bindings. Everything worked well until I added a pivot two pivots with the same title, let's call them C and C', and A an B two different pivots, ordered like this: AC'BC. Now, when I try to go from B to C everything is OK. But when I go from A to C, it does strange things: doesn't move, moves the titles but not the content... weird.

I debugged the SelectionChanged event in the PivotControl, and it's even weirdest. It's called two times: the first, a transition from C to another pivot and then another call which contains the right transition, from A to C.

I've tried everything. The databinding is a list of structs, like this:

struct Resource
{
   public someenum Type;
   public string Data;
   public string Identifier { get {...} set {...} }
   public UserToken User;
}

The title of the pivot is set by a IValueConverter, which takes the string Identifier (which is a function of Type, Data and User) as the parameter. I changed it to make the titles always different, but it still does not work. For example, when Type and Data are the same there are error, although Identifier and User are different.

I have written both operators == and != for Resource, and also for UserToken. They behave as they should, but still does this weird transition.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

很酷不放纵 2025-01-10 09:12:27

陈述显而易见的事情:给它们起不同的名字。

如果它们不同,您应该给它们不同的名称。只需用计数器后固定名称即可。

编辑

来自MSDN:

名称是极少数不能更改的依赖属性之一
动画(IsAnimationProhibited 在元数据中为 true),因为名称
其本身对于动画的定位至关重要。数据绑定名称是
技术上可行,但这是一种极其罕见的情况,因为
数据绑定名称不能满足主要预期目的
属性:为代码隐藏提供标识符连接点。

Stating the obvious: give them different names.

If they are different you should give them different names. Just post-fix the name with a counter.

EDIT

From the MSDN:

Name is one of the very few dependency properties that cannot be
animated (IsAnimationProhibited is true in metadata), because the name
itself is vital for targeting an animation. Data binding a Name is
technically possible, but is an extremely uncommon scenario because a
data-bound Name cannot serve the main intended purpose of the
property: to provide an identifier connection point for code-behind.

清音悠歌 2025-01-10 09:12:27

刚刚找到答案。经过大量谷歌搜索后,我注意到 GetHashCode 可能与这个混乱的情况有关。我修改了结构体中 getHashCode 的定义,瞧!它工作顺利:)

只是一个提示:要获得一个好的 GetHashCode 函数,请返回该函数的易失性参数的 XOR。就我而言,代码是这样的:

Type.GetHashCode() ^ Data.GetHashCode() ^ User.GetHashCode();

Just found the answer. After a lot of googling, I noticed that maybe GetHashCode had something to do in this mess. I modified the definition of getHashCode in the struct and, voilá! It works smoothly :)

Just a tip: to get a good GetHashCode function return a XOR of the volatile parameters of the function. In my case, the code was this:

Type.GetHashCode() ^ Data.GetHashCode() ^ User.GetHashCode();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文