相关疑难解决方法(0)

从datatemplate内部绑定到viewmodel

我有多个视频显示它们与Mainviewmodel中的视频选择绑定.一切正常,直到我尝试将enter命令绑定到Mainviewmodel.我不知道这个的语法.目前,绑定设置为Video而不是Mainviewmodel.

错误信息:

'StartVideoCommand' property not found on 'object' ''Video'   
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

wpf binding datatemplate itemtemplate viewmodel

23
推荐指数
2
解决办法
1万
查看次数

标签 统计

binding ×1

datatemplate ×1

itemtemplate ×1

viewmodel ×1

wpf ×1