0

ラベル付けされたコンボ ボックスであるユーザー コントロールがあります。デバッグを通じて、ユーザー コントロールを含むビューを開くたびに、各モデル プロパティへの get 要求が前回よりも 1 つ多いことに気付きました。

ビューが開かれるたびにモデルを再インスタンス化します (理由については特に言及する必要はありません)。このバインドによってプログラムにまだ結び付けられているため、正しく破棄されることはありません! 依存関係プロパティへの複数のバインドを維持できることはありがたいのですが、どうすればこれを停止できますか?

私が考えた2つの考慮事項:

1)ビューが閉じられたときにユーザーコントロールが破棄されていません。可能であれば、破棄されていることを確認する必要がありますか? それとも、これは WPF のニーズに対してやり過ぎですか?

2) ビューが開かれるたびにモデルを再インスタンス化する代わりに、モデルの別のインスタンスを実際に作成するのではなく、すべてのプロパティを転送するモデルの基本クラスにコピー関数を実装する必要がありますか?

どう思いますか?

ありがとう

4

1 に答える 1

0

Finally fixed this problem, the issue was not limited to my user controls but in fact all controls (including the standard WPF ones) with bindings! When the window was being closed the bindings were not being terminated, this bug/issue/design (maybe it has a use - although I can't see what that would be) seems very strange to me. Initially I did think maybe it was the way I set the bindings up, however with one of the bindings to a normal text box I simply use Text="{Binding name}" - no other configuration defined which could be causing this issue!

Anyway, the solution I found was to add BindingOpertations.ClearAllBindings(this) to the windows closing event. Hope this helps if you are having this problem.

于 2013-10-07T12:13:44.367 に答える