-
Notifications
You must be signed in to change notification settings - Fork 780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Win81] Exception on Toggle in/out of view #1
Comments
From @tibel via codeplex: a better workaround is to set CacheViews property to false in the constructor. |
Hi,
fe.Parent is null here (VisualTreeHelper.GetParent(view) also is), but when adding it to the content of a ContentControl, the exception "Element is already the child of another element." is thrown anyway. Maybe the view is still the child of an unloaded ContentPresenter and thus is not in the visual tree (so Parent is null)? I did not find a solution to this problem yet. |
Given what you've found I'm not sure if this will be solvable, with Parent being null we have no access to the ContentPresenter previously containing the view to try and detach it. |
There is actually a way to prevent the Exception without workarounds: public class SomePageViewModel : Conductor<ItemViewModel>.Collection.AllActive
{
public SomePageViewModel()
{
Items.AddRange(
Enumerable.Range(0, 1)
.Select(i => new ItemViewModel { DisplayName = "Item" + i }));
}
} The explanation is a bit longer (maybe @nigel-sampson can help here)? |
The problem is not Summary:
|
I'm relooking at this, I've encountered the same error in a different way, there's definitely something fishy with the xaml stack here. That being said there are ways around it. @rufusl the solution from @tibel to activate and deactivate the view models in question would help remove this bug (as deactivate clears the views). |
I've added a work around to View that if a view returned from LocateForModel fails we fall back to LocateForModelType that resolves this issue. Still working with Microsoft on why this is happening. |
In Win8.1, if you have a ItemsControl derived type that removes and re-adds some portion of its children and you're using the c:View.Model binding on a data template to convert child view models into their views, you hit an issue.
The issue is this. The OnModelChanged event gets fired every time that the child appears or disappears, which in and of itself would not be bad. However, the following pattern is then employed ...
The problem lies in that the ViewLocator attempts to use a cached view by default and that view is still part of the visual tree. Therefore, the setting the content property fails because the view is already the child of another element in the tree.
This has been tested with several Syncfusion controls that employ this visual hiding/reshowing.
The workaround is to add this override, which trades out the exception (and failure to display the view-model with instead a memory increase as the view keeps being created.
The text was updated successfully, but these errors were encountered: