Bindable base和视图模型的问题 [英] Issue with Bindable base and a view model

查看:33
本文介绍了Bindable base和视图模型的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的应用程序上使用viewmodels,每次导航到一个视图时,我都会将datacontext设置为等于e.paramater。

I'm using viewmodels on my application, and each time I navigate to a view I set the datacontext to equal e.paramater.

我遇到的问题当用户单击后退按钮时。这显然使用相同的视图模型,但它重新连接所有绑定,并且据我所知,添加了对"公共事件PropertyChangedEventHandler PropertyChanged;"的订阅。 event
,它是可绑定库的一部分。

The issue I'm having is when a user clicks the back button. This obviously uses the same view model, but it re-wires all the binding, and as far as I can tell adds subscriptions to the  "public event PropertyChangedEventHandler PropertyChanged;" event which is part of bindable base.

我遇到的问题是,往返几次会导致事件订阅量大幅增加。

The issue I have is that going back and forward a few times results in a huge increase in the event subscriptions.

除了显而易见的内存问题之外,这也是一个问题,但它确实会导致绑定到滑块的任何更改属性抛出参数异常(Value不属于预期范围。) - 只有在您加载页面,将
导航到另一个页面,按回来,然后再次更改滑块时才会发生这种情况。我的理解是,这是因为有一个事件仍然连接到一个不再可见的滑块。

Apart from the obvious memory issue this would be an issue, however it does cause any changing properties bound to a slider to throw an argument exception (Value does not fall within the expected range.) - this only happens if you load the page, navigate away to another page, press back, then change the slider again. My understanding is that this occurs because there is an event still wired up to a slider no longer visible.

我对WPF太新了,不知道我是否应该删除事件订阅PropertyChagned事件 - 但如果我应该,如何,如果我不应该是这是地铁中的错误?

I'm too new to WPF to know if I should be removing event subscriptions to the PropertyChagned event - but if I should be, how, and if I shouldn't be is this a bug in metro?

推荐答案

是的,这是已知错误,解决方法是删除活动订阅。 我在这里的另一篇文章讨论了同样的问题。
Yes, this is a known bug, and the workaround is to remove the event subscriptions.  I have another post on here somewhere which discusses this same issue.


这篇关于Bindable base和视图模型的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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