2013-08-15 35 views
19

Mam wiele wyświetlanych filmów wideo, które są związane z kolekcją wideo w Mainviewmodel. Wszystko działa dobrze, dopóki nie spróbuję powiązać polecenia enter z Mainviewmodel. Nie znam składni tego. W tej pozycji powiązanie jest ustawione na Video, a nie Mainviewmodel.Wiązanie z viewmodelem z wnętrza matrycy

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 

Odpowiedz

22
Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=DataContext.StartVideo}" 
+1

miałem do wiązania się z polecenia dlatego nie: 'komend = "{Binding RelativeSource = {RelativeSource AncestorType = {X: Wpisz UserControl}}, Path = DataContext.COMMAND_I_WANT_TO_BIND_TO} "' –