TextEditorOption throw “Object reference not set to an instance of an object” when VM is destructed

Đang mở
#352 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
csharp
Lĩnh vực
desktop

Hướng nghiên cứu

Bắt đầu với WPF TabControl.ContentTemplate được hiển thị và liên kết Options trên TextEditorEx. Tái hiện việc xóa một view model khỏi DocList trong khi Options đang được liên kết, sau đó theo dõi sự kiện OptionsChanged gây ra ngoại lệ tham chiếu null. Hoàn tất khi việc đóng một tab không còn gây ra ngoại lệ trong quá trình xóa view model.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

I'm working on a notepadplus-like editor with avalonEdit.
I made a control class based on avalonedit and put it in a tab control template like this:

<TabControl Grid.Row="3"  ItemsSource="{Binding DocList}" SelectedItem="{Binding SelectedItem,Mode=TwoWay}" >
            <TabControl.ItemTemplate>
                <DataTemplate>
                </DataTemplate>
            </TabControl.ItemTemplate>
            <TabControl.ContentTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.Resources>
                            <avalonEdit:TextEditorOptions x:Key="TextEditOptions" />
                        </Grid.Resources>
                        <controls:TextEditorEx x:Name="avEditor"
                                Background="White"
                                Foreground="Black"
                                LineNumbersForeground="Black"
                                ShowLineNumbers="{Binding ShowLineNumbers, UpdateSourceTrigger=PropertyChanged}"
                                IsModified="{Binding Path=IsDirty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                SyntaxHighlighting="{Binding HighlightingDefinition, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                                Document="{Binding Document, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                                Column="{Binding SynchronizedColumn,Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"
                                Line="{Binding SynchronizedLine,Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"
                                FontSize="{Binding SynchronizedFontSize, UpdateSourceTrigger=PropertyChanged}"
                                FontFamily="{Binding SynchronizedFontFamily, UpdateSourceTrigger=PropertyChanged}"
                                Options="{Binding TextEditorOptionsSetting, FallbackValue={StaticResource TextEditOptions}}"
                                >
                        </controls:TextEditorEx>
                    </Grid>
                </DataTemplate>
            </TabControl.ContentTemplate>
        </TabControl>

and DocList is a list of viewmodel for controls:TextEditorEx, when click close btn of tab , certain vm will be removed from DocList.
it works fine until i bind Options to VM,when VM is removed from DocList, it triggers OptionsChanged Event and throws “Object reference not set to an instance of an object”.

I'm new to MVVM and WPF so how can I fix this problem? It seems to me the View Model should be destruct AFTER control does.

Ngôn ngữ chính
C#
Star
2.1k
Fork
496
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của icsharpcode/AvalonEdit

Tất cả issue của icsharpcode/AvalonEdit

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.