I have a TabControl bound to a collection and a DataTemplate for the TabItems. It works pretty well, but now I want to bind Button's CommandTarget to textEditor on currently selected TabItem. How can I achive that?
<TabControl Name="tabs" Grid.Row="1" Margin="0,5,0,0"
ItemsSource="{Binding Tabs, Mode=OneTime}">
<TabControl.ContentTemplate>
<DataTemplate DataType="vm:TabViewModel">
<avalon:TextEditor Name="textEditor"
Document="{Binding Document, Mode=OneWay}" Margin="3"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto"/>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
I didn't find an elegant way to resolve this issue, but there are few workarounds. First to find controls from DataTemplate you must use VisualTreeHelper to find child of TabControl. Then you can pack this mechanism to custom IValueConverter, behavior or viewmodel and pass as CommandTarget