2013-08-15 73 views
19

Tôi có nhiều video được hiển thị chúng bị ràng buộc với một đoạn video trong Mainviewmodel. Mọi thứ hoạt động tốt cho đến khi tôi thử ràng buộc lệnh nhập vào Mainviewmodel. Tôi không biết cú pháp cho việc này. Vì nó là viết tắt của ràng buộc được thiết lập để Video và không Mainviewmodel.Ràng buộc xem mô hình từ bên trong một bảng dữ liệu

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 

Trả lời

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

tôi đã liên kết với một lệnh do đó tôi đã làm: 'Command =" {Binding RelativeSource = {RelativeSource AncestorType = {x: Nhập UserControl}}, Đường dẫn = DataContext.COMMAND_I_WANT_TO_BIND_TO} "' –