开发者

WPF ListView item selection unchecks checkbox

开发者 https://www.devze.com 2023-02-12 11:07 出处:网络
I have a this code: <ListView Grid.Row=\"0\" Grid.Column=\"0\" Margin=\"5\" HorizontalAlignment=\"Stretch\" Name=\"netcastListView\" ItemsSource=\"{Binding NetcastList}\">

I have a this code:

        <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>

When I select an item in the listview, it unchecks the checkbox which bleeds through to the binding. How can I prevent this?

Edit / Clarification: What I want to prevent is the checkbox from being affected when the item is selected.


If you don't need to modify the checkbox, then change the binding to OneWay and/or set IsEnabled on the checkbox to False

0

精彩评论

暂无评论...
验证码 换一张
取 消