2013-08-15 55 views
19

Birden fazla videonuz var, bunlar Mainviewmodel'de video koleksiyonuna bağlı. Her şey iyi çalışıyor, Mainviewmodel'e giriş komutunu bağlamaya çalışıyorum. Bunun için sözdizimini bilmiyorum. Bu, bağlayıcı olarak Mainviewmodel değil Video olarak ayarlanır.Bir modemin içinden görüntü modeme bağlama

errorMessage:

'StartVideoCommand' property not found on 'object' ''Video' 

Xaml: `Komuta =" {Binding RelativeSource = {RelativeSource AncestorType = {x:

<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 

cevap

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

Bir komuta nedenle yaptım bağlamak zorunda: UserControl yazın}}, Yol = DataContext.COMMAND_I_WANT_TO_BIND_TO} "' –