如何绑定到列表视图中显示并被双击的数据模板?
我想要这样的东西:
<CheckBox Grid.Column="1" Grid.Row="5" Command="{Binding AddItemCommand}"></CheckBox>
我已经完成了所有工作,但不知道如何将命令绑定到列表视图中的数据模板或该数据模板中的网格。
数据模板是这样的:
<DataTemplate x:Key="ServerViewItemTemplate" DataType="ViewModel:ServerViewModel">
<Border BorderBrush="Black" BorderThickness="1" Margin="10">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="70" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="20" />
<RowDefinition Height="20" />
<RowDefinition Height="20" />
<RowDefinition Height="20" />
<RowDefinition Height="20" />
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Text="ServerId:" FontWeight="Bold"/>
<TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding ServerId}" FontWeight="Bold"/>
<TextBlock Grid.Column="0" Grid.Row="1" Text="Login:"/>
<TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding Login}" />
<TextBlock Grid.Column="0" Grid.Row="2" Text="Password:"/>
<TextBlock Grid.Column="1" Grid.Row="2" Text="{Binding Password}" />
<TextBlock Grid.Column="0" Grid.Row="3" Text="Type:"/>
<TextBlock Grid.Column="1" Grid.Row="3" Text="{Binding Type}" />
<TextBlock Grid.Column="0" Grid.Row="4" Text="IpAddress:"/>
<TextBlock Grid.Column="1" Grid.Row="4" Text="{Binding IpAddress}" />
<TextBlock Grid.Column="0" Grid.Row="5" Text="Include:"/>
<CheckBox Grid.Column="1" Grid.Row="5" Command="{Binding AddItemCommand}"></CheckBox>
</Grid>
</Border>
</DataTemplate>
所以如果它被双击它应该调用ICommand,和在CheckBox AddItemCommand中一样。