19
У меня появилось несколько видеороликов, они связаны видеоконференцией в Mainviewmodel. Все работает отлично, пока я не попытаюсь связать команду ввода с Mainviewmodel. Я не знаю синтаксиса для этого. Поскольку это означает, что для привязки установлено значение «Видео», а не «Mainviewmodel».Привязка к viewmodel изнутри datatemplate
ErrorMessage:
'StartVideoCommand' property not found on 'object' ''Video'
Xaml:
<Window.Resources>
<local:MainViewModel x:Key="MainViewModel"/>
</Window.Resources>
<Grid DataContext="{StaticResource MainViewModel}">
<ListBox ItemsSource="{Binding Videos}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.InputBindings>
!!! <KeyBinding Key="Enter" Command="{Binding StartVideo}" /> !Bound to Video not to Mainviewmodel grrr
</Grid.InputBindings>
... layout stuff
<TextBlock Text="{Binding Title}" Grid.Column="0" Grid.Row="0" Foreground="White"/>
<TextBlock Text="{Binding Date}" Grid.Column="0" Grid.Row="1" Foreground="White" HorizontalAlignment="Left"/>
<TextBlock Text="{Binding Length}" Grid.Column="1" Grid.Row="1" Foreground="White" HorizontalAlignment="Right"/>
... closing tags
Я должен был связываться с командой поэтому я сделал: 'Command =" {Binding RelativeSource = {RelativeSource AncestorType = {х: Тип UserControl}}, Path = DataContext.COMMAND_I_WANT_TO_BIND_TO} "' –