WPF ListView项目选择取消选中复选框

时间:2011-02-22 20:04:07

标签: wpf listview gridview mvvm checkbox

我有一个代码:

        <ListView Grid.Row="0" Grid.Column="0" Margin="5" HorizontalAlignment="Stretch" Name="netcastListView" ItemsSource="{Binding NetcastList}">
            <ListView.View>
                <GridView>
                    <GridViewColumn Width="Auto">
                        <GridViewColumnHeader Content="Sync" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox IsChecked="{Binding IsSynced}" Command="{Binding Source={StaticResource mainViewModel}, Path=UpdateNetcastCommand}" CommandParameter="{Binding}" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="Auto">
                        <GridViewColumnHeader Content="Netcast" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding ShowTitle}" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
        </ListView>

当我在列表视图中选择一个项目时,它会取消选中导致绑定的复选框。我该如何防止这种情况?

编辑/澄清: 我想要阻止的是当选中该项时,复选框会受到影响。

1 个答案:

答案 0 :(得分:0)

如果您不需要修改该复选框,请将约束更改为OneWay和/或将IsEnabled复选框设置为False