-
Description To Reproduce /// ParentView.xaml
[...]
<ContentControl s:View.Model="{Binding DynamicControl}" [...] />
[...] /// ParentViewModel.cs
public class ParentViewModel : Screen
{
private Func<ChildViewModel> createChild;
private Screen dynamicControl;
public ParentViewModel(Func<ChildViewModel> createChild) { this.createChild = createChild; }
public Screen DynamicControl
{
get => this.dynamicControl;
set => this.SetAndNotify(ref this.dynamicControl, value);
}
protected override void OnInitialActivate()
{
base.OnInitialActivate();
this.DynamicControl = this.createChild();
}
}
/// ChildViewModel.cs
public class ChildViewModel : Screen
{
protected override void OnInitialActivate()
{
// Never gets called
}
} Version Info
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
(Converted this support request to a discussion. Please read the issue template). The parent doesn't know that the child exists. How would it? It's therefore impossible to know that there's something which needs to be activated. You can use a You can also use |
Beta Was this translation helpful? Give feedback.
(Converted this support request to a discussion. Please read the issue template).
The parent doesn't know that the child exists. How would it? It's therefore impossible to know that there's something which needs to be activated.
You can use a
Conductor<IScreen>
, and setActiveItem
rather than having aDynamicItem
property: the conductor knows that theActiveItem
property contains a child which needs to be activated/etc. See the documentation.You can also use
child.ConductWith(parent)
for long-lived children, but don't do this if the child might be destroyed before the parent.