locked
[UWP]TwoWay Binding Throws StackOverflow Exception RRS feed

  • Question

  • Hi All,

    I am facing StackOverflowException when I bound Collectionviewsource to the ListBox using TwoWay DataBinding

    But the issue does not get reproduced while using OneWay DataBinding.

    Please find the error reproducing line from the below

      <ListBox  ItemsSource="{x:Bind InspectionItemsViewSource.Source,Mode=TwoWay}"….>

    If this binding is OneWay then there is no problem

    Please suggest me any solution.

    Thanks,

    M.Sugapriya


    • Edited by Xavier Xie-MSFT Thursday, August 11, 2016 7:41 AM general title tag
    Wednesday, August 10, 2016 4:46 PM

Answers

  • Hi Sugapriya M,

    As far as I know, “x:Bind” still has some issues in UWP. You could use “Binding” as a workaround. And you would need to implement INotifyPropertyChanged interface.

    I have edited your code, please refer to my following code for reference:

    <UserControl
        x:Class="Accordion.Controls.InspectionItemListView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:Accordion.Controls"
       
        xmlns:data="using:Accordion.Model"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        d:DesignHeight="300"
        d:DesignWidth="400">
    
        <Grid>
           
    
    
            <ListBox x:Name="InspectionItemsListView"
                                    ItemsSource="{Binding InspectionItemsViewSource.Source,Mode=TwoWay}"
                                   Margin="12,12" ScrollViewer.ZoomMode="Disabled" 
                                    BorderThickness="0,0,0,1"                        
                                    RequestedTheme="Light"                               
                                    ScrollViewer.BringIntoViewOnFocusChange="True"
                                    TabNavigation="Local"
                               
                                    >
    
                <ListBox.ItemTemplate>
                    <DataTemplate>
    
                        <Grid Margin="0,0,0,0">
                            <ListView>
                                <ListViewItem Content="Name 0"/>
                                <ListViewItem Content="Name 1"/>
                                <ListViewItem Content="Name 2"/>
                                <ListViewItem Content="Name 3"/>
                            </ListView>
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
    
    
        </Grid>
    </UserControl>
    
    public sealed partial class InspectionItemListView : UserControl,INotifyPropertyChanged
        {
            public List<GroupedQueryResults> _inspectionItemsGrouped;
            private List<GroupedQueryResults> inspectionItemsGrouped
            {
                get { return _inspectionItemsGrouped; }
                set
                {
                    _inspectionItemsGrouped = value;
                    RaisePropertyChanged("inspectionItemsGrouped");
                }
    
            }
    
            private CollectionViewSource _InspectionItemsViewSource;
            public CollectionViewSource InspectionItemsViewSource
            {
                get { return _InspectionItemsViewSource; }
                set
                {
                    _InspectionItemsViewSource = value;
                    RaisePropertyChanged("InspectionItemsViewSource");
                }
    
            }
    
            public InspectionItemListView()
            {
                
    
                this.InitializeComponent();
                InspectionItemsViewSource = new CollectionViewSource();
                this.DataContext = this;
            }
    
            public event PropertyChangedEventHandler PropertyChanged;
    
            private void RaisePropertyChanged(string name)
            {
                if (PropertyChanged != null)
                {
                    PropertyChanged(this,new PropertyChangedEventArgs(name));
                }
            }
    
            public void SetItemsSource(ObservableCollection<InspectionItem> inspectionItems)
            {
    
                inspectionItemsGrouped = inspectionItems.GroupBy(item => item.SubCategory).Select(g => new GroupedQueryResults
                {
                    SubCategory = g.Key,
                    Items = g.ToList(),
                    CountGroup = g.Count(),
                    ValidCount = g.Sum(c => c.IsValid ? 1 : 0)
                }).ToList();
    
                
                InspectionItemsViewSource.Source = inspectionItemsGrouped;            
            }
    
       
    
    
        }

    Best Regards,

    Xavier Eoro


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, August 16, 2016 8:40 AM

All replies

  • Hi Sugapriya M,

    Welcome to the Developing Universal Windows apps forum!

    Please read the sticky posts, especially the Guide to posting: subject line tags and Known Issues for Windows 10 SDK and Tools  

    I have added tag for you this time, and you would need to add tag to title by yourself next time.

    I have tried to make a simple code sample to reproduce your issue. But I cannot reproduce it. Could you please upload a reproducible code sample to OneDrive and post link here? I would help you locate this issue.

    The following is my code:

    <ListBox  ItemsSource="{x:Bind InspectionItemsViewSource.Source,Mode=TwoWay}"/>
    public CollectionViewSource InspectionItemsViewSource { get; set; }
            public MainPage()
            {
                this.InitializeComponent();
                InspectionItemsViewSource = new CollectionViewSource();
                List<string> ls = new List<string>();
                ls.Add("sasa");
                ls.Add("sasa");
                ls.Add("sasa");
                InspectionItemsViewSource.Source = ls;
                this.DataContext = this;
            }

    Best Regards,

    Xavier Eoro


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, August 11, 2016 8:02 AM
  • Hi Xavier,

    Thank you for update.

    I have attached part of my application and please download the sample from the below link

    Sample: https://drive.google.com/open?id=0B3G6ZAB2A_gUaXZNNVdnNlpCYlE

    Thanks,

    M.Sugapriya

    Thursday, August 11, 2016 12:24 PM
  • Hi Xavier,

    Thank you for update.

    I have attached part of my application and please download the sample from the below link

    Sample: https://drive.google.com/open?id=0B3G6ZAB2A_gUaXZNNVdnNlpCYlE

    Thanks,

    M.Sugapriya

    Hi Sugapriya M,

    Thank you for you reply.

    I would test your sample in my side. If I got any useful information, I would update here in time.

    Best Regards,

    Xavier Eoro


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, August 15, 2016 11:58 AM
  • Hi Sugapriya M,

    As far as I know, “x:Bind” still has some issues in UWP. You could use “Binding” as a workaround. And you would need to implement INotifyPropertyChanged interface.

    I have edited your code, please refer to my following code for reference:

    <UserControl
        x:Class="Accordion.Controls.InspectionItemListView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:Accordion.Controls"
       
        xmlns:data="using:Accordion.Model"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        d:DesignHeight="300"
        d:DesignWidth="400">
    
        <Grid>
           
    
    
            <ListBox x:Name="InspectionItemsListView"
                                    ItemsSource="{Binding InspectionItemsViewSource.Source,Mode=TwoWay}"
                                   Margin="12,12" ScrollViewer.ZoomMode="Disabled" 
                                    BorderThickness="0,0,0,1"                        
                                    RequestedTheme="Light"                               
                                    ScrollViewer.BringIntoViewOnFocusChange="True"
                                    TabNavigation="Local"
                               
                                    >
    
                <ListBox.ItemTemplate>
                    <DataTemplate>
    
                        <Grid Margin="0,0,0,0">
                            <ListView>
                                <ListViewItem Content="Name 0"/>
                                <ListViewItem Content="Name 1"/>
                                <ListViewItem Content="Name 2"/>
                                <ListViewItem Content="Name 3"/>
                            </ListView>
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
    
    
        </Grid>
    </UserControl>
    
    public sealed partial class InspectionItemListView : UserControl,INotifyPropertyChanged
        {
            public List<GroupedQueryResults> _inspectionItemsGrouped;
            private List<GroupedQueryResults> inspectionItemsGrouped
            {
                get { return _inspectionItemsGrouped; }
                set
                {
                    _inspectionItemsGrouped = value;
                    RaisePropertyChanged("inspectionItemsGrouped");
                }
    
            }
    
            private CollectionViewSource _InspectionItemsViewSource;
            public CollectionViewSource InspectionItemsViewSource
            {
                get { return _InspectionItemsViewSource; }
                set
                {
                    _InspectionItemsViewSource = value;
                    RaisePropertyChanged("InspectionItemsViewSource");
                }
    
            }
    
            public InspectionItemListView()
            {
                
    
                this.InitializeComponent();
                InspectionItemsViewSource = new CollectionViewSource();
                this.DataContext = this;
            }
    
            public event PropertyChangedEventHandler PropertyChanged;
    
            private void RaisePropertyChanged(string name)
            {
                if (PropertyChanged != null)
                {
                    PropertyChanged(this,new PropertyChangedEventArgs(name));
                }
            }
    
            public void SetItemsSource(ObservableCollection<InspectionItem> inspectionItems)
            {
    
                inspectionItemsGrouped = inspectionItems.GroupBy(item => item.SubCategory).Select(g => new GroupedQueryResults
                {
                    SubCategory = g.Key,
                    Items = g.ToList(),
                    CountGroup = g.Count(),
                    ValidCount = g.Sum(c => c.IsValid ? 1 : 0)
                }).ToList();
    
                
                InspectionItemsViewSource.Source = inspectionItemsGrouped;            
            }
    
       
    
    
        }

    Best Regards,

    Xavier Eoro


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, August 16, 2016 8:40 AM