I have bound a WPF TreeView to an ObservableCollection. When a Connection node gets expanded in the UI, I want Connection.GetDatabases() to be called, which returns an collection of Databases.
I’m using HierarchicalDataTemplate:
<HierarchicalDataTemplate DataType="{x:Type dbcore:Connection}" ItemsSource="<WHAT GOES HERE?>">
<StackPanel Orientation="Horizontal">
<Image Source="{StaticResource DataServerIcon}" Margin="5,2" />
<TextBlock Text="{Binding Converter={StaticResource connToStringConverter}}" />
</StackPanel>
</HierarchicalDataTemplate>
But because I want to use a method instead of a property, I’m not sure what to use in the ItemsSource property.
Since you want to get the values when the item is expanded you cannot do it in XAML at design time. You can do it when you your item is expanded in code behind: