Page 1 of 1

Binding errors when clearing a bound ObservableCollection [Manage C# SDK 2.2.4]

Posted: 17 Oct 2019, 00:36
by darthmaule2
If I have a List with a bunch of elements...
        List<string> TestSet1 = new List<string>()
        {
            "one",
            "two",
            "three",
            "four",
            "five",
        };
And an ObservableCollection initialized to that List of items...
        public ObservableCollection<string> MyCollection   {   get;   }
        ...
        MyCollection   = new ObservableCollection<string>(TestSet1);     
Display them in the view...
        <ListBox
            Background="White"
            ItemsSource="{Binding MyCollection}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <TextBlock Width="206" Height="50" TextAlignment="Left" TextTrimming="CharacterEllipsis" Text="{Binding}" >
                        </TextBlock>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
 
And then later I clear the collection (or even if I remove them individually):
MyCollection.Clear();
I get these 4 lines of errors for each items cleared from the collection...

[NOESIS/E] Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='ItemsControl', AncestorLevel='1'
[NOESIS/E] Binding failed: Path=VerticalContentAlignment, Source=null(''), Target=ListBoxItem(''), TargetProperty=Control.VerticalContentAlignment
[NOESIS/E] Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='ItemsControl', AncestorLevel='1'
[NOESIS/E] Binding failed: Path=HorizontalContentAlignment, Source=null(''), Target=ListBoxItem(''), TargetProperty=Control.HorizontalContentAlignment


We do this a lot in our application and so it results in massive amounts of errors streaming by.

Is this a bug in Noesis or is there another way I should be doing this?

Thanks.

Re: Binding errors when clearing a bound ObservableCollection [Manage C# SDK 2.2.4]

Posted: 17 Oct 2019, 16:15
by darthmaule2
This also happens if I just set "MyCollection" to another ObservableCollection.

Re: Binding errors when clearing a bound ObservableCollection [Manage C# SDK 2.2.4]

Posted: 17 Oct 2019, 18:24
by steveh
I had the same issue in our game when I created my own derived version of a listboxitem. The error comes from NoesisTheme.xaml in the style for the listboxitem:
    <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource DefaultControlStyle}">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="BorderBrush" Value="Transparent"/>
        <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
        <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
I "fixed" it in ours by creating our own style and changing the way it binds the HorizontalContentAlignment.

Re: Binding errors when clearing a bound ObservableCollection [Manage C# SDK 2.2.4]

Posted: 17 Oct 2019, 20:56
by sfernandez
Those messages occur when disconnecting the ListBoxItem from the items host panel.
I checked in WPF and it is not showing this kind of message when removing the items, so we should do the same.
Could you please report it in our bugtracker, thanks.

Re: Binding errors when clearing a bound ObservableCollection [Manage C# SDK 2.2.4]

Posted: 18 Oct 2019, 11:49
by darthmaule2

Re: Binding errors when clearing a bound ObservableCollection [Manage C# SDK 2.2.4]

Posted: 18 Oct 2019, 13:56
by sfernandez
Thanks for the report.