- darthmaule2
- Posts: 98
- Joined:
Binding errors when clearing a bound ObservableCollection [Manage C# SDK 2.2.4]
If I have a List with a bunch of elements...
And an ObservableCollection initialized to that List of items...
Display them in the view...
And then later I clear the collection (or even if I remove them individually):
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.
Code: Select all
List<string> TestSet1 = new List<string>()
{
"one",
"two",
"three",
"four",
"five",
};
Code: Select all
public ObservableCollection<string> MyCollection { get; }
...
MyCollection = new ObservableCollection<string>(TestSet1);
Code: Select all
<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>
Code: Select all
MyCollection.Clear();
[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
- Posts: 98
- Joined:
Re: Binding errors when clearing a bound ObservableCollection [Manage C# SDK 2.2.4]
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]
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:
I "fixed" it in ours by creating our own style and changing the way it binds the HorizontalContentAlignment.
Code: Select all
<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}}}"/>
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Binding errors when clearing a bound ObservableCollection [Manage C# SDK 2.2.4]
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.
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.
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Binding errors when clearing a bound ObservableCollection [Manage C# SDK 2.2.4]
Thanks for the report.
Who is online
Users browsing this forum: Google [Bot] and 63 guests