1

Closed

LongListSelector can‘t Binding data to IsFlatList

description

The Code is
<toolkit:LongListSelector x:Name="SongsList"
                                     ItemsSource="{Binding Source={StaticResource Locator}, Path=MainMusic.SongItems.Items}" Background="Transparent"
                                      IsFlatList="{Binding  Source={StaticResource Locator}, Path=MainMusic.SongItems.IsMini}" 
                                      ItemTemplate="{StaticResource SongItemTmpl}"
                                      GroupHeaderTemplate="{StaticResource GroupHeader}"
                                      GroupItemTemplate="{StaticResource GroupItem}"
                                      GroupViewClosing="citiesListGropus_GroupViewClosing"
                                      GroupViewOpened="citiesListGropus_GroupViewOpened">
                    <toolkit:LongListSelector.GroupItemsPanel>
                        <ItemsPanelTemplate>
                            <toolkit:WrapPanel Orientation="Horizontal"/>
                        </ItemsPanelTemplate>
                    </toolkit:LongListSelector.GroupItemsPanel>
                </toolkit:LongListSelector>
the error message is
"Set property 'Microsoft.Phone.Controls.LongListSelector.IsFlatList' threw an exception. [Line: 182 Position: 47]".
 
 
I'm sure that the data I binding is True.
even if I change the property IsFlatList in the codebehind,it didn't work!
Closed Apr 4, 2012 at 2:10 AM by shawnoster
I'm unable to get this to repro, can you please attach a very simple repro? I did a simple example where I set IsFlatList in XAML to True and databound ItemsSource and it worked without any issues.Closing for now, if you can attach a simple example that shows the issue please re-open and we'll investigate. Thank you.

comments

MrTatt wrote Apr 25, 2012 at 10:29 AM

The problem is setting the Property IsFlatList using a binding. Setting it to true or false in XAML works perfectly. However, binding it to a property of type bool will throw the exception hkflyor mentioned above.

rasheedb wrote Aug 16, 2012 at 3:23 AM

Download the source code and replace the property IsFlatList in the LongListSelector.cs with the following. Reason you are getting the error is because the current property is not a dependency property and cannot be bind to in XAML. Making it a dependency property will allow you to bind to it in XAML.

region IsFlatList Dependency Property

    /// <summary>
    /// Controls whether or not the Grouping is shown.
    /// </summary>
    public bool IsFlatList {
        get { return (bool)GetValue(IsFlatListProperty); }
        set { SetValue(IsFlatListProperty, value); }
    }

    /// <summary>
    /// The IsFlatList DependencyProperty.
    /// </summary>
    public static readonly DependencyProperty IsFlatListProperty =
        DependencyProperty.Register("IsFlatList", typeof(bool), typeof(LongListSelector), new PropertyMetadata(true, OnIsFlatListChanged));


    private static void OnIsFlatListChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) {
        ((LongListSelector)obj).OnItemsSourceChanged();
    }

    #endregion