✅ Stylet MVVM OnInitialActivate isn't called
I want to add subdirectories to Items collection and display them in
NavigationPaneView
ShellView
TreeViewTreeView on view loading, I tried OnInitialActivateOnInitialActivate, but method isn't executed. Is there any solution?public class NavigationPaneViewModel : Screen
{
public BindableCollection<NavigationPaneItem> Items { get; set; }
protected override void OnInitialActivate()
{
base.OnInitialActivate();
Items.Clear();
Items.AddRange(GetSubDirectories(_path));
}
...
}public class NavigationPaneViewModel : Screen
{
public BindableCollection<NavigationPaneItem> Items { get; set; }
protected override void OnInitialActivate()
{
base.OnInitialActivate();
Items.Clear();
Items.AddRange(GetSubDirectories(_path));
}
...
}NavigationPaneView
<UserControl x:Class="Explorer.Views.NavigationPaneView"
...
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=viewModels:NavigationPaneViewModel, IsDesignTimeCreatable=false}"
d:DesignHeight="450" d:DesignWidth="250">
<DockPanel>
<TreeView ItemsSource="{Binding Items}">
<TreeView.Resources>
<HierarchicalDataTemplate
DataType="{x:Type models:NavigationPaneItem}"
ItemsSource="{Binding Children}"
>
<TextBlock Text="{Binding Name}"/>
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
</DockPanel>
</UserControl><UserControl x:Class="Explorer.Views.NavigationPaneView"
...
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=viewModels:NavigationPaneViewModel, IsDesignTimeCreatable=false}"
d:DesignHeight="450" d:DesignWidth="250">
<DockPanel>
<TreeView ItemsSource="{Binding Items}">
<TreeView.Resources>
<HierarchicalDataTemplate
DataType="{x:Type models:NavigationPaneItem}"
ItemsSource="{Binding Children}"
>
<TextBlock Text="{Binding Name}"/>
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
</DockPanel>
</UserControl>ShellView
<Window x:Class="Explorer.Views.ShellView"
...
d:DataContext="{d:DesignInstance Type=viewModels:ShellViewModel, IsDesignTimeCreatable=False}"
Title="{Binding Title}" Height="450" Width="960">
<DockPanel>
<Grid>
...
<ContentControl s:View.Model="{Binding NavigationPane}" Grid.Column="0" Padding="0,5"/>
<GridSplitter Grid.Column="1" Width="1" Background="Transparent"/>
<views:ContentPaneView Grid.Column="2"/>
</Grid>
</DockPanel>
</Window><Window x:Class="Explorer.Views.ShellView"
...
d:DataContext="{d:DesignInstance Type=viewModels:ShellViewModel, IsDesignTimeCreatable=False}"
Title="{Binding Title}" Height="450" Width="960">
<DockPanel>
<Grid>
...
<ContentControl s:View.Model="{Binding NavigationPane}" Grid.Column="0" Padding="0,5"/>
<GridSplitter Grid.Column="1" Width="1" Background="Transparent"/>
<views:ContentPaneView Grid.Column="2"/>
</Grid>
</DockPanel>
</Window>