简体   繁体   中英

Is there a limit to how many times a property can be bound to in Silverlight?

I have an scenario where a bunch of data needs to be displayed in a grid but it uses column groups and row groups in such a complicated manner such that we can't use a datagrid. What we have is have section groups in rows A, B, and C with vertical column groups c1 and c2. And 2 versions of this control may be displayed.

There can be up to 5 of A. Each A can have up to 5 of B, each B has 8 C's, and each C has 5 properties in c1 and 5 properties in c2.

Each of those B's prints out the label for C, and then all values for that label for c1, then all properties for that label under c2.

Each C can be hidden, shown, or highlighted controlled by a indeterminate checkbox outside of the grid.

The problem I'm having is that around the 5th A, all the Cs underneath it begin to lose their binding to the checkbox (bound via relative binding).

Is there a limit to how many times a property can be bound to such that it simply stops evaluating the bindings? Each C has their own checkbox and they all give out about the same time. Thing is it's all an ItemsControl so it's on the last iteration - nothing changes from the first 4 times it's all done, it's just the 5th iteration of the control.

If I remove one of the Cs such that there's less to process the problem goes away. If I add another, the problem occurs earlier.

I've drawn up a quick image to show what I'm talking about here: 在此处输入图片说明 Notice that any of the C can be highlighted or hidden. But after a certain point the problem is that the highlighting and hiding simply stops. No errors, exceptions, nothing in the output window. The binding simply stops being evaluated.


UPDATE :

It appears there is a limit. If I use the following xaml to test:

        <ItemsControl ItemsSource="{Binding TestCollection}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Index}" Visibility="{Binding DataContext.TestVisibility, RelativeSource={RelativeSource AncestorType=navigation:Page}}" />
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>

and populate it like so in my viewmodel:

        List<TestModelObject> initList = new List<TestModelObject>();
        for (int i = 0; i < 15000; i++)
        {
            initList.Add(new TestModelObject(i));
        }

        TestCollection = new ObservableCollection<TestModelObject>(initList);

and set TestVisibility to false in my ViewModel. After running it and letting it process since adding 15K items to the UI at once takes a moment I get a list if integers in my ItemsControl starting around 9640. However, if I reload I get a slightly different number each time. Is it based upon execution time?

I tested this both in Silverlight 5, and in Silverlight 4. For silverlight 4 I of course used a workaround for RelativeBinding but the results were the same.

To my knowlage, there isn't and shoulden't be a binding limit.

If i where to guess, I would say your overrideing Equals or GetHashCode on your C's. (Or because you are using the same instance of C multiple times in the same container, not clear if your doing that or not). When multiple items are equal to each other, or equal items aren't equal that should be or similar some very weird things realated to selection can happen, sort of how you described above. Make sure that each C instance will produce unique equality and/or hashcode values.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM