I tried to reproduce the problem you describe, but it didn't work for me.
My example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Core2022.SO.freasy
{
public class Field
{
public int Number { get; } = random.Next();
private static readonly Random random = new Random();
public static IEnumerable<Field> GetRandomFields()
=> Enumerable.Range(0, random.Next(10, 20)).Select(_ => new Field()).ToList().AsReadOnly();
}
}
using Simplified;
using System.Collections.Generic;
namespace Core2022.SO.freasy
{
public class FieldsViewModel : BaseInpc
{
private IEnumerable<Field> _fields = Field.GetRandomFields();
private RelayCommand? _refreshFields;
public IEnumerable<Field> Fields { get => _fields; set => Set(ref _fields, value); }
public RelayCommand RefreshFields => _refreshFields
??= new RelayCommand(_ => Fields = Field.GetRandomFields());
private Field? _selectedField;
public Field? SelectedField
{
get => _selectedField;
set => Set(ref _selectedField, value);
}
}
}
<Window x:Class="Core2022.SO.freasy.FieldsWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Core2022.SO.freasy" xmlns:sys="clr-namespace:System;assembly=netstandard"
mc:Ignorable="d"
Title="FieldsWindow" Height="450" Width="800">
<Window.DataContext>
<local:FieldsViewModel/>
</Window.DataContext>
<Window.Resources>
<sys:String x:Key="null">No Selected Field</sys:String>
</Window.Resources>
<UniformGrid Columns="2">
<ListBox x:Name="listBox" ItemsSource="{Binding Fields}"
DisplayMemberPath="Number"
SelectedItem="{Binding SelectedField}"
VerticalAlignment="Center" HorizontalAlignment="Center"/>
<UniformGrid Columns="1">
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center">
<TextBlock.Text>
<PriorityBinding>
<Binding Path="SelectedField.Number" Mode="OneWay"/>
<Binding Source="{StaticResource null}"/>
</PriorityBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center">
<TextBlock.Text>
<PriorityBinding>
<Binding Path="SelectedItem.Number" Mode="OneWay" ElementName="listBox"/>
<Binding Source="{StaticResource null}"/>
</PriorityBinding>
</TextBlock.Text>
</TextBlock>
<Button Content="Refresh Collection" Command="{Binding RefreshFields}"
VerticalAlignment="Center" HorizontalAlignment="Center" Padding="15 5"/>
</UniformGrid>
</UniformGrid>
</Window>
Perhaps you missed an important detail of your implementation in the explanations, which is the cause of the error you described.
Try changing my simple example to reproduce your problem.
BaseInpc and RelayCommand classes.
Source Code Archive: freasy.7z