AvalonEdit icon indicating copy to clipboard operation
AvalonEdit copied to clipboard

System.InvalidOperationException:“Document is null”

Open zangetsudo opened this issue 2 months ago • 1 comments

xmlns:avalonEdit="http://icsharpcode.net/sharpdevelop/avalonedit"

<TabControl Grid.Row="1" ItemsSource="{Binding FileSearchTableTemplates, Mode=OneWay}" SelectedItem="{Binding SelectedTab, Mode=TwoWay}" SelectedIndex="{Binding SelectedIndex}"
ContentTemplateSelector="{StaticResource selector}"> <TabControl.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Header}" VerticalAlignment="Center"/> </StackPanel> </DataTemplate> </TabControl.ItemTemplate> </TabControl>

<local:FileSearchViewSelector x:Key="selector" BasicFileMergeTemplate="{StaticResource BasicFileMergeVMTemplate}" AdvancedFileSearchTemplate="{StaticResource AdvancedFileSearchVMTemplate}" />

AdvancedFileSearchVMTemplate is: <DataTemplate x:Key="AdvancedFileSearchVMTemplate" DataType="{x:Type viewModels:AdvancedFileSearchVM}"> ...skip others... <avalonEdit:TextEditor x:Name="TextEditor" Grid.Row="1" Document="{Binding Document}" SyntaxHighlighting="{x:Null}" ShowLineNumbers="True" WordWrap="False" FontFamily="Consolas" FontSize="12" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" behaviors:TextEditorExtension.Register="{Binding RegisterEditorCommand}" /> ...skip others...
<DataTemplate>

a new tab item (B) is created after the search button was clicked. the backgroud task is runing and update the TextEditor with :: editor?.BeginChange(); try { updateAction?.Invoke(); } finally { editor.EndChange(); if (_autoScroll) editor.ScrollToEnd(); }

updateAction: Document.Text = value;

if we switch to tab item A, the system is crashed : System.InvalidOperationException:“Document is null” if we dont switch to A, say stay with B, it's ok... we can add code to check if Document is null but it's not the case.

please, any help will be appreciated.

zangetsudo avatar Dec 04 '25 01:12 zangetsudo

TabControl: SelectedItem="{Binding SelectedTab, Mode=TwoWay}" SelectedIndex="{Binding SelectedIndex}"
ContentTemplateSelector="{StaticResource selector}"> <TabControl.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Header}" VerticalAlignment="Center"/> </StackPanel> </DataTemplate> </TabControl.ItemTemplate>

zangetsudo avatar Dec 04 '25 01:12 zangetsudo