System.InvalidOperationException:“Document is null” #445

Open
opened 2025-12-03 19:05:47 -06:00 by zangetsudo · 1 comment
zangetsudo commented 2025-12-03 19:05:47 -06:00 (Migrated from github.com)

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


<TabControl.ItemTemplate>





</TabControl.ItemTemplate>

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

AdvancedFileSearchVMTemplate is:

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

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.

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 commented 2025-12-03 19:07:32 -06:00 (Migrated from github.com)

TabControl:
SelectedItem="{Binding SelectedTab, Mode=TwoWay}"
SelectedIndex="{Binding SelectedIndex}"
ContentTemplateSelector="{StaticResource selector}">
<TabControl.ItemTemplate>





</TabControl.ItemTemplate>

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>
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-icsharpcode/AvalonEdit#445
No description provided.