C
C#9mo ago
Alex

✅ Stylet MVVM OnInitialActivate isn't called

I want to add subdirectories to Items collection and display them in TreeView on view loading, I tried OnInitialActivate, 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>
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server