C# WPF-在DataGridRow上选择设置为赢得';t更改绑定对象中的值

C# WPF-在DataGridRow上选择设置为赢得';t更改绑定对象中的值,c#,wpf,datagrid,wpfdatagrid,C#,Wpf,Datagrid,Wpfdatagrid,我遇到的问题是,我试图使用具有多个选择的DataGrid,并且我试图在不按Ctrl键的情况下选择多个 我认为: <DataGrid Grid.Row="1" ItemsSource="{Binding Tags}" SelectionMode="Extended" SelectionUnit="FullRow" AutoGenerateColumns="False" SelectedRows ="{Binding Sel

我遇到的问题是,我试图使用具有多个选择的DataGrid,并且我试图在不按Ctrl键的情况下选择多个

我认为:

<DataGrid Grid.Row="1" ItemsSource="{Binding Tags}" SelectionMode="Extended" SelectionUnit="FullRow" AutoGenerateColumns="False"
                                   SelectedRows ="{Binding SelectedTags, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                   CanUserAddRows="False">

        <DataGrid.ItemContainerStyle>
            <Style TargetType="{x:Type DataGridRow}">
                <Setter Property="IsSelected" Value="{Binding IsSelected}"/>
            </Style>
        </DataGrid.ItemContainerStyle>
        <DataGrid.RowStyle>
            <Style TargetType="{x:Type DataGridRow}">
                <EventSetter Event="PreviewMouseDown" Handler="DataGridRowPreviewMouseDownHandler"></EventSetter>
            </Style>
        </DataGrid.RowStyle>
        <DataGrid.Columns>
            <DataGridCheckBoxColumn
                 Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=DataGridRow}, Mode = TwoWay}"
                 MaxWidth="25" MinWidth="25">
                <DataGridCheckBoxColumn.CellStyle>
                    <Style TargetType="DataGridCell">
                        <Setter Property="VerticalAlignment" Value="Center" />
                    </Style>
                </DataGridCheckBoxColumn.CellStyle>
            </DataGridCheckBoxColumn>
        </DataGrid.Columns>
    </DataGrid>
我的模范班是

public class Tags : INotifyPropertyChanged
{
    private bool _isSelected;
    public bool IsSelected
    {
        get { return _isSelected; }
        set { _isSelected = value; RaisePropertyChanged("IsSelected"); }
    }

    public int ID { get; set; }

    #region INotifyPropertyChanged
    public event PropertyChangedEventHandler PropertyChanged;

    public void RaisePropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    #endregion
}
GridView的上下文是一个ObservableCollection

问题是当我在DataGridRowPreviewMouseDownHandler中设置

row.IsSelected=!第1行:选举产生

模型未更新

没有DataGridRowPreviewMouseDownHandler,一切都可以正常工作。使用它,初始绑定不起作用(例如,如果我在添加到ObservableCollection时将一个标记的IsSelected设置为true,它将显示为NotSelected)。知道为什么吗


如何触发绑定对象到行的更新?

是否尝试将SelectionMode=“Extended”添加到数据网格并检查其行为?它位于项目源后的第一行。问题是,使用SelectionMode=“Extended”可以选择多行,但必须按Ctrl键。我正在尝试在不按Ctrl键的情况下实现相同的行为。我的问题可能与此类似的示例重复,即绑定不再工作,UI看起来很好,但绑定属性不反映UI中显示的内容。您是否尝试添加SelectionMode=“Extended”到您的datagrid并检查行为?它位于项目源后面的第一行。问题是,使用SelectionMode=“Extended”可以选择多行,但必须按Ctrl键。我试图在不按Ctrl键的情况下实现相同的行为。我的问题的可能重复之处在于,按照与此类似的示例,绑定不再工作,UI看起来很好,但绑定属性不反映UI中显示的内容。
public class Tags : INotifyPropertyChanged
{
    private bool _isSelected;
    public bool IsSelected
    {
        get { return _isSelected; }
        set { _isSelected = value; RaisePropertyChanged("IsSelected"); }
    }

    public int ID { get; set; }

    #region INotifyPropertyChanged
    public event PropertyChangedEventHandler PropertyChanged;

    public void RaisePropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    #endregion
}