WPF DataGrid, application crash when adding a row

前端 未结 6 1675
青春惊慌失措
青春惊慌失措 2021-02-08 02:29

I have a wpf datagrid bound to a TrackableCollection. In some rare occations, and for only a few selected users, the application will crash when the user adds a new record by en

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-08 03:00

    I had the same issue with touch screen only. I had a WPF app that was working fine until I connected the touch screen that the app was built for.

    This issue occur when the DataGrid selected item was bounded to an object that was null;

    I resolved it this way:

    The DataGrid Xaml had this line:

    SelectedItem="{Binding SelItem}"
    

    The XVVM looked like:

    public MyViewModel SelItem
    {
    
        get
        {
            if (m_selected == null)
                 return new MyViewModel();
            else
                 return m_selected;
        }
    }
    

提交回复
热议问题