darthmaule2
Topic Author
Posts: 98
Joined: 23 Oct 2014, 19:54

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

17 Oct 2019, 00:36

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.
 
darthmaule2
Topic Author
Posts: 98
Joined: 23 Oct 2014, 19:54

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

17 Oct 2019, 16:15

This also happens if I just set "MyCollection" to another ObservableCollection.
 
steveh
Posts: 42
Joined: 07 Oct 2019, 12:50

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

17 Oct 2019, 18:24

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.
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

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

17 Oct 2019, 20:56

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.
 
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

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

18 Oct 2019, 13:56

Thanks for the report.

Who is online

Users browsing this forum: Google [Bot] and 63 guests