I have a treeview in my xaml as below. I use the selected item by using interactivity and bind the event.
<DataTemplate x:Key="TreeTemplate">
<TreeView Name="TreeView" ItemsSource="{Binding ItemList}" ItemTemplate="{StaticResource ChildTemplate}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectedItemChanged">
<i:InvokeCommandAction
Command="{Binding SetSelectedItemCommand}"
CommandParameter="{Binding SelectedItem, ElementName=TreeView}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TreeView>
</DataTemplate>
This all works very well except when by application loads for the first time. Even if SelectedItem property is set on startup, the treeview does not show the item highlighted unless a mouse event is fired which causes SelectedItemChanged event. Any ideas as as to how can I do this?
My datacontext is in code behind of the xaml
myView = new MyViewModel();
this.DataContext = myView;
InitializeComponent();