Skip to content

Commit 5480d86

Browse files
destroy templates after model setted
1 parent fd96986 commit 5480d86

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

UnityWeld/Binding/TemplateBinding.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,18 @@ private void InitializeTemplate()
7777

7878
// Get value from view model.
7979
var viewModelPropertyValue = viewModelProperty.GetValue(ViewModel, null);
80-
if (viewModelPropertyValue == null)
80+
if (viewModelPropertyValue != null)
8181
{
82-
throw new PropertyNullException($"TemplateBinding cannot bind to null property in view: {ViewModelPropertyName}.");
82+
//some times property for binding can be null ( for example we must destroy our template ) and this case not wrong
83+
//throw new PropertyNullException($"TemplateBinding cannot bind to null property in view: {ViewModelPropertyName}.");
84+
InstantiateTemplate(viewModelPropertyValue);
8385
}
86+
}
8487

85-
InstantiateTemplate(viewModelPropertyValue);
88+
protected override void OnTemplateDestroy(Template template)
89+
{
90+
base.OnTemplateDestroy(template);
91+
Destroy(template.gameObject);
8692
}
8793
}
8894
}

0 commit comments

Comments
 (0)